Created
February 7, 2011 13:05
-
-
Save mislav/814326 to your computer and use it in GitHub Desktop.
Reloads a specific Safari extension in development
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'appscript' | |
# Extensions to reload. | |
# TODO: read exts currently in development from TextMate | |
exts = ["Instapaper Editing"] | |
Appscript::app("Safari").activate | |
safari = Appscript::app("System Events").processes["Safari"] | |
safari.menu_bars[1].menu_bar_items["Develop"].menus[1].menu_items["Show Extension Builder"].click | |
sleep 0.5 | |
builder = safari.windows["Extension Builder"] | |
ui = builder.scroll_areas[1].UI_elements[1] | |
num_reloaded = 0 | |
(1..ui.groups.count).each do |i| | |
# static text representing the extension name | |
text = ui.groups[i].static_texts[1] | |
if text.exists | |
name = text.name.get | |
# is this an extension that needs to be reloaded? | |
if exts.include? name | |
puts "Reloading #{name.inspect}..." | |
ui.UI_elements["ReloadUninstall#{name}"].buttons["Reload"].click | |
# give Safari some breathing room after reload | |
sleep 0.5 | |
break if (num_reloaded += 1) == exts.length | |
end | |
end | |
# HACK: press the down cursor key to cycle through extensions | |
ui.keystroke("\037") | |
# give it some time to update the view | |
sleep 0.2 | |
end | |
# FIXME: doesn't work | |
# builder.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment