Class: AppleLoad
- Inherits:
-
Object
- Object
- AppleLoad
- Includes:
- AppleScript
- Defined in:
- lib/appleload.rb,
lib/appleload/version.rb,
lib/appleload/applescript.rb
Defined Under Namespace
Modules: AppleScript
Constant Summary collapse
- LOCATION =
"/Applications/Xcode.app/Contents/Applications/Application Loader.app"- IOS_SUFFIX =
" (iOS App)"- VERSION =
"0.1.0"
Class Method Summary collapse
Instance Method Summary collapse
- #enable_accessibility! ⇒ Object
-
#initialize ⇒ AppleLoad
constructor
A new instance of AppleLoad.
- #list ⇒ Object
- #open_app! ⇒ Object
- #open_delivery ⇒ Object
- #quit_app! ⇒ Object
- #upload(title, ipa_path) ⇒ Object
- #with_gui(&block) ⇒ Object
Methods included from AppleScript
Constructor Details
#initialize ⇒ AppleLoad
20 21 22 |
# File 'lib/appleload.rb', line 20 def initialize enable_accessibility! end |
Class Method Details
.list ⇒ Object
12 13 14 |
# File 'lib/appleload.rb', line 12 def self.list new.list end |
.upload(*args) ⇒ Object
16 17 18 |
# File 'lib/appleload.rb', line 16 def self.upload(*args) new.upload(*args) end |
Instance Method Details
#enable_accessibility! ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/appleload.rb', line 24 def enable_accessibility! # see https://gist.github.com/lacostej/3868129 `sudo sh -c "/bin/echo -n \"a\" > /private/var/db/.AccessibilityAPIEnabled"` `sudo chmod 444 /private/var/db/.AccessibilityAPIEnabled` # see http://apple.stackexchange.com/a/122405 ["/Applications/iTerm.app", "/Applications/Utilities/Terminal.app"].each do |app| bundle_id = `/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' #{app}/Contents/Info.plist`.strip sql_cmd = %Q{sudo sqlite3 '/Library/Application Support/com.apple.TCC/TCC.db' "INSERT OR REPLACE INTO access VALUES('kTCCServiceAccessibility','#{bundle_id}',0,1,1,NULL);" } `#{sql_cmd}` end end |
#list ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/appleload.rb', line 73 def list with_gui do self.open_delivery titles = applescript(%Q{ set menuItemTitles to "" activate application "Application Loader" tell application "System Events" tell process "Application Loader" tell window 1 tell pop up button 1 delay 1 key code 49 # space bar delay 1 count menu items of menu 1 set menuItemTitles to name of menu items of menu 1 end tell end tell end tell end tell return menuItemTitles }).gsub("Choose..., ", "").split(", ").map(&:strip).map { |string| without_suffix = string.split(IOS_SUFFIX).first version = without_suffix.split(" ")[-1] title = without_suffix.split(" ")[0..-1].join(" ") { title: title, version: version, type: :ios } } end end |
#open_app! ⇒ Object
49 50 51 52 |
# File 'lib/appleload.rb', line 49 def open_app! `open -a #{LOCATION.shellescape}` sleep 2 end |
#open_delivery ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/appleload.rb', line 59 def open_delivery applescript %Q{ tell application "System Events" activate tell process "Application Loader" tell radio group 1 of window 1 click button "Deliver Your App" delay 3 end tell end tell end tell} sleep 2 end |
#quit_app! ⇒ Object
54 55 56 57 |
# File 'lib/appleload.rb', line 54 def quit_app! applescript('tell application "Application Loader" to quit') sleep 2 end |
#upload(title, ipa_path) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/appleload.rb', line 108 def upload(title, ipa_path) ipa_path = File.(ipa_path) title = title[0..25] # only first 25 chars with_gui do self.open_delivery applescript(%Q{ set menuItemTitles to "" set menuItemToSelect to "#{title}" set ipaPath to "#{ipa_path}" activate application "Application Loader" tell application "System Events" tell process "Application Loader" tell window 1 tell pop up button 1 delay 1 key code 49 # space bar delay 1 click (menu item 1 where its name starts with menuItemToSelect) of menu 1 delay 1 end tell click button "Next" delay 1 click button "Choose..." tell application "System Events" keystroke "g" using {shift down, command down} keystroke ipaPath delay 3 keystroke return delay 3 keystroke return end tell delay 2 click button "Send" repeat until exists button "Next" delay 1 end repeat click button "Next" repeat until exists button "Done" delay 1 end repeat click button "Done" end tell end tell end tell }) true end end |
#with_gui(&block) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/appleload.rb', line 37 def with_gui(&block) open_app! begin result = yield quit_app! result rescue Exception => e quit_app! raise e end end |