Skip to content

Instantly share code, notes, and snippets.

@Capncavedan
Created May 28, 2012 01:46
Show Gist options
  • Save Capncavedan/2816784 to your computer and use it in GitHub Desktop.
Save Capncavedan/2816784 to your computer and use it in GitHub Desktop.
AppleScript to assist with scheduling changes in Backblaze backup speed
#!ruby
VALID_SPEED_DESCRIPTORS = %w(slow medium fast unlimited 0 10 20 30 40 50 60 70 80 90 100)
def applescript_for_speed(descriptor)
speed = case descriptor.to_s.downcase
when "slow"
"20"
when "medium"
"40"
when "fast"
"70"
when "unlimited"
"100"
else
descriptor.to_s
end
unless VALID_SPEED_DESCRIPTORS.include?(speed)
puts "Call with an argument: #{VALID_SPEED_DESCRIPTORS}"
exit
end
script = <<EOT
tell application "System Preferences" to activate
tell application "System Events"
tell process "System Preferences"
click menu item "Backblaze Backup" of the menu "View" of menu bar 1
click button "Settings..." of the first group of the window "Backblaze Backup"
click radio button "Performance" of the first tab group of the front sheet of the window "Backblaze Backup"
set value of the first value indicator of the first slider of the first tab group of the first sheet of the window "Backblaze Backup" to #{speed}
click button "OK" of the first sheet of the window "Backblaze Backup"
end tell
end tell
tell application "System Preferences" to quit
EOT
script.gsub('"', '\"')
end
`osascript -e "#{ applescript_for_speed( ARGV[0] ) }"`
# in /etc/crontab
# maximum Backblaze during wee hours
0 0 * * * danb /usr/bin/ruby /Users/danb/bin/backsimmer.rb 100 > /dev/null 2>&1;
# medium Backblaze during morning and daytime hours
0 6 * * * danb /usr/bin/ruby /Users/danb/bin/backsimmer.rb 40 > /dev/null 2>&1;
# slow Backblaze during evening hours
0 17 * * * danb /usr/bin/ruby /Users/danb/bin/backsimmer.rb 20 > /dev/null 2>&1;
@nocturne1
Copy link

Exactly what I was looking for. Thanks!

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