Skip to content

Instantly share code, notes, and snippets.

@hiilppp
Created April 16, 2014 19:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hiilppp/10922752 to your computer and use it in GitHub Desktop.
Save hiilppp/10922752 to your computer and use it in GitHub Desktop.
AppleScript to lock your Mac's screen, pause iTunes (if playing), and sync OmniFocus (if open). (Use EventScripts to automatically trigger script when a Bluetooth device (e.g., your iPhone) leaves your Mac's range: http://www.mousedown.net/mouseware/EventScripts.html)
do shell script "defaults write com.apple.screensaver askForPassword 1; defaults write com.apple.screensaver askForPasswordDelay 0"
repeat until (do shell script "defaults read com.apple.screensaver askForPassword") = "1" and (do shell script "defaults read com.apple.screensaver askForPasswordDelay") = "0"
delay 0.5
end repeat
tell application "ScreenSaverEngine" to activate
if application "iTunes" is running then
tell application "iTunes"
if player state is playing then
set initial_sound_volume to the sound volume
set i to initial_sound_volume
repeat until i = 0
set i to i - 1
set sound volume to i
delay 0.1
end repeat
pause
set sound volume to initial_sound_volume
end if
end tell
end if
if application "OmniFocus" is running then
tell first document of application "OmniFocus"
synchronize
(*
repeat until syncing is false
delay 0.1
end repeat
do shell script "date \"+%-d.%-m.%Y, %-H:%M:%S\" > \"$HOME/Dropbox/var/lib/of/ls.txt\""
*)
end tell
end if
@hiilppp
Copy link
Author

hiilppp commented Apr 16, 2014

Cf. entering_range.scpt: https://gist.github.com/hiilppp/10922837

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment