// Name: Set Volume Level // Description: Sets system volume to a specified level. // Author: tayiorbeii import '@johnlindquist/kit' /** * Defines the available volume levels as an array of objects, * each with a display name and a numerical value between 0 and 1 */ const volumeLevels = [ { name: '5%', value: 0.05 }, { name: '10%', value: 0.1 }, { name: '20%', value: 0.2 }, { name: '50%', value: 0.5 }, ]; /** * Presents a selection prompt to the user, allowing them to choose a volume level */ const selectedVolume = await arg( "Select volume level:", volumeLevels.map(level => level.name) );/** * Finds the volume level object that matches the user's selection. */ const selectedLevel = volumeLevels.find(level => level.name === selectedVolume); if (selectedLevel) { /** * Executes an AppleScript command to set the system volume to the selected level. */ await exec(`osascript -e "set volume output volume ${selectedLevel.value}"`); } else { /** * Displays an error message if the selected volume level is not found. */ console.error("Invalid volume level selected."); await div("Invalid volume level selected."); }