Reputation: 17746
Is there a way to check if the screen saver is running using AppleScript?
Currently I'm using the following AppleScript to start the screen saver:
tell application "System Events"
start current screen saver
end tell
I found this script but I don't know if that's correct or how to write that into my script.
What I want is something like this:
tell application "System Events"
if screen saver is not activated then
start current screen saver
end if
end tell
Upvotes: 1
Views: 914
Reputation: 51
I know it's a bit late now but for others trying similar things.
I used the following recently in a shell script linked to a cronjob.
# check if screen saver is running
saverActive=$(osascript -e "tell application \"System Events\"" -e "get running of screen saver preferences" -e "end tell")
if [ "$saverActive" = "true" ]; then
echo "Screen saver is running"
osascript -e "tell application \"System Events\" to stop current screen saver"
osascript -e "tell application \"System Events\" to start current screen saver"
else
echo "Screen saver is not running"
fi
This script was used in the context of periodically changing the screensaver.
Upvotes: 1
Reputation: 19032
Try this...
tell application "System Events"
if not (running of screen saver preferences) then start current screen saver
end tell
Upvotes: 0