Skip to content

Instantly share code, notes, and snippets.

@gsong
Created February 17, 2012 06:13
Show Gist options
  • Save gsong/1851146 to your computer and use it in GitHub Desktop.
Save gsong/1851146 to your computer and use it in GitHub Desktop.
AppleScript to start/stop CrashPlan
log "Deciding what to do with CrashPlan…"
set isCrashPlanRunning to false
try
set pid to do shell script "sudo launchctl list | grep com.crashplan.engine" ¬
user name "@{admin_user}" password "@{admin_password}" ¬
with administrator privileges
set isCrashPlanRunning to true
end try
if isCrashPlanRunning then
log "CrashPlan is already running: " & pid
else
log "CrashPlan is not currently running…"
end if
set acStatus to do shell script "pmset -g ac"
if acStatus is "No adapter attached." then
log "Computer is running on battery…"
set isPluggedIn to false
else
log "Computer is plugged in…"
set isPluggedIn to true
end if
if isCrashPlanRunning and not isPluggedIn then
run script POSIX file "@directory/unload_crashplan.scpt"
else if isPluggedIn and not isCrashPlanRunning then
log "Loading CrashPlan engine…"
do shell script "launchctl load -w /Library/LaunchDaemons/com.crashplan.engine.plist" ¬
user name "@{admin_user}" password "@{admin_password}" ¬
with administrator privileges
else
log "Nothing needs to be done."
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment