How can I successively trigger an AppleScript very quickly?
Solution 1:
Adding > /dev/null 2>&1 &
to the end of the do shell script
command should work. This redirects the stdout
and stderr
of the do shell script
command to /dev/null
and runs the shell script in the background, meaning that AppleScript no longer needs to wait for the command to return stdout
or stderr
before the AppleScript script can finish. That means that it finishes and can be run again much more quickly.
You also shouldn't need the try
handler at the beginning. The following modified script should work:
set currentVolume to output volume of (get volume settings)
set volume output volume (currentVolume + 2)
-- play volume changing sound at new volume
do shell script "afplay /System/Library/LoginPlugins/BezelServices.loginPlugin/Contents/Resources/volume.aiff > /dev/null 2>&1 &"
I got this tip from MacScripter (an excellent resource for AppleScripting) in a post about running multiple instances of a shell script.
Solution 2:
How about adding an ampersand to the end of the afplay
line so the scripted part plays in background? Like this
afplay /System/Library/LoginPlugins/BezelServices.loginPlugin/Contents/Resources/volume.aiff &