Total n00b. I have searched for a ready-made solution to my needs, including on this forum, but with no luck. Perhaps you genii can help? (I last programmed seriously with BBC Basic, although I’ve tweaked some bits of Perl etc. on web sites - nothing adventurous and certainly nothing from scratch.)
Situation: I have two iMacs in a corridor at work, for general use by our volunteer staff. They’re primarily used to check web mail, surf the 'Net etc.
Problem: some folks tend to quit the Safari application when they walk away from the computer. But I would like it to be available immediately for the next user.
Objective: an Applescript, I suppose, that will detect when Safari has been quit and, after a short delay, tell Finder to start it again and display the appropriate home page as set in Safari’s preferences.
Additional: I don’t want to prevent the user from quitting the application. I don’t want an ‘unquittable’ kiosk effect. I want folks to be able to enjoy the Mac experience - up to a point.
If anyone has a moment to either point me in the direction of resources that can help me make this happen, or simply tell me how to do it, you’d make me very happy.
–Mike–
Model: iMac
Browser: Safari 531.21.10
Operating System: Mac OS X (10.6)
This will check if Safari is open every 60 seconds.
Save the script as an ‘application bundle’ on Tiger or Leopard or an ‘application’ on Snow Leopard.
When you Save the script, make sure you check-mark ‘Stay Open’.
You can set it as a login script in your ‘System Preferences’ > ‘Accounts’ > ‘Login Items’ pane.
If you want it to run in the background (not display in the Dock) - go here. http://scriptbuilders.net/files/ibackgroundscripts1.4.1.html
on idle
tell application "System Events" to set foo to (exists process "Safari")
if foo then -- Safari is running
return 60 -- seconds -- adjust to your liking
else
tell application "Safari" to activate
end if
end idle
Tom
Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)
It probably doesn’t make much difference here, but ideally, an idle handler should always return a specified result:
on idle
tell application "System Events" to set foo to (exists process "Safari")
if not foo then -- Safari is not running
tell application "Safari" to activate
end if
return 60 -- seconds -- adjust to your liking
end idle
the most elegant (and inexpensive) way is a launchd agent.
It restarts Safari immediately after it has been quit
[code]<?xml version="1.0" encoding="UTF-8"?>
Label
com.keep.Safari.open
ProgramArguments
/Applications/Safari.app/Contents/MacOS/Safari
KeepAlive
[/code]
save the code as plain text UTF-8 encoded in ~/Library/LaunchAgents/com.keep.Safari.open.plist
and activate the agent with
[code]launchctl -w load ~/Library/LaunchAgents/com.keep.Safari.open.plist[/code]