An einem wunderschönen Abend haben mein Kollege und ich eine kleine Anwendung im AppStore veröffentlicht. Das Veröffentlichen einer Anwendung ist ein ziemlich langer Prozess und besteht aus vielen Phasen. Eine der Phasen ist die Vorbereitung von Bildern für den App Store. Die Aufgabe ist auf den ersten Blick einfach: Die Anwendung im Simulator zu starten und einen Screenshot der Anwendung zu erstellen. Wir benötigen jedoch Bildschirme in sechs Sprachen in verschiedenen Größen mit einer Demonstration von fünf verschiedenen Zuständen der Anwendung. Eine Stunde lang können Sie es schaffen, indem Sie einfach mit den Händen fotografieren, Kaffee trinken und allgemeine Themen diskutieren. Aber wir sind Programmierer und es ist nicht unsere Methode, dies von Hand zu tun. Wir müssen den Prozess automatisieren. Obwohl wir das nie getan haben, haben wir es getan. Wir haben gelernt, wie einfach es ist, MacOS-Anwendungen programmgesteuert zu verwalten. Und sie haben AppleScript geschrieben, mit dem die XCode- und Simulator-Apps ausgeführt werden.
Inszenierung
. 6 , iPhone iPad. - . , . iPhone , iPad , .
Automator.
.
WorkFlow - . . Actions - . WorkFlow. WorkFlow . WorkFlow.
, , - , . . Automator . WorkFlow, - Run AppleScript.
, , Run AppleScript, , Run JavaScript Run Shell Script. WorkFlow , Workflow (Run WorkFlow).
Run AppleScript , . . . AppleScript. - .
, , .
XCode. - . Xcode , Xcode , .
sizes.
set ipad to "iPad Pro (12.9-inch) (3rd generation)"
set sizes to {"iPhone 8 Plus", "iPhone 11 Pro Max", ipad}
schemes
set schemes to {"TinyApp", "TinyApp-cn", "TinyApp-jp", "TinyApp-es", "TinyApp-de", "TinyApp-ru", "TinyApp-fr"}
:
repeat with size in sizes
repeat with lang in schemes
-- .....
end repeat
end repeat
size, lang.
XCode , , Simulator:
tell application "Xcode" to activate
tell application "System Events"
tell process "Xcode"
tell menu bar 1
tell menu "Product"
tell menu item "Scheme"
tell menu "Scheme"
click menu item lang
end tell
end tell
tell menu item "Destination"
tell menu "Destination"
click menu item size
end tell
end tell
click menu item "Run"
end tell
end tell
end tell
end tell
:
tell application "System Events"
display dialog "Continue"
end tell
, , () Continue. , Continue.
, .
tell application "Automator" to activate
tell application "System Events"
tell process "Simulator"
tell menu bar 1
tell menu "File"
click menu item "Save Screen"
end tell
end tell
end tell
end tell
:
tell application "Finder"
set the source_folder to (path to desktop folder) as alias
sort (get files of source_folder) by creation date
set theFile to (item 1 of reverse of result) as alias
set newName to lang & "-" & size & " .png"
set name of theFile to newName
end tell
iPad :
if size as string is equal to ipad then
tell application "Automator" to activate
tell application "System Events"
tell process "Simulator"
tell menu bar 1
tell menu "Hardware"
tell menu item "Orientation"
tell menu "Orientation"
click menu item "Landscape Right"
end tell
end tell
end tell
delay 2
tell menu "File"
click menu item "New Screen Shot"
end tell
tell application "Finder"
set the source_folder to (path to desktop folder) as alias
sort (get files of source_folder) by creation date
set theFile to (item 1 of reverse of result) as alias
set newName to lang & "-" & size & "-landscape" & " .png"
set name of theFile to newName
end tell
tell menu "Hardware"
tell menu item "Orientation"
tell menu "Orientation"
click menu item "Portrait"
end tell
end tell
end tell
end tell
end tell
end tell
end if
. , . , . - AppStore.
Natürlich könnten wir auch das Kopieren von Dateien automatisieren, aber wir haben dort aufgehört.
Ergebnis
Anstatt alle 120 Bilder mit unseren Händen in ungefähr einer Stunde zu erstellen, lernten wir den Umgang mit Automator, nachdem wir drei Stunden damit verbracht hatten, das Programm und die AppleScript-Sprache zu beherrschen, und unser Skript ermöglichte es uns, 120 Bilder pro Minute mit einem Minimum an Vorgängen zu generieren. Trotz des langen Zeitaufwands waren wir zufrieden. Ich hoffe, unsere Erfahrung kann für andere Menschen und für andere Aufgaben nützlich sein.
Und hier ist der Code vollständig:
on run {input, parameters}
set ipad to "iPad Pro (12.9-inch) (3rd generation)"
set sizes to {"iPhone 8 Plus", "iPhone 11 Pro Max", ipad}
set schemes to {"TinyApp", "TinyApp-cn", "TinyApp-jp", "TinyApp-es", "TinyApp-de", "TinyApp-ru", "TinyApp-fr"}
repeat with size in sizes
repeat with lang in schemes
tell application "Xcode" to activate
tell application "System Events"
tell process "Xcode"
tell menu bar 1
tell menu "Product"
tell menu item "Scheme"
tell menu "Scheme"
click menu item lang
end tell
end tell
tell menu item "Destination"
tell menu "Destination"
click menu item size
end tell
end tell
click menu item "Run"
end tell
end tell
end tell
end tell
tell application "System Events"
display dialog "Continue"
end tell
tell application "Automator" to activate
tell application "System Events"
tell process "Simulator"
tell menu bar 1
tell menu "File"
click menu item "Save Screen"
end tell
end tell
end tell
end tell
tell application "Finder"
set the source_folder to (path to desktop folder) as alias
sort (get files of source_folder) by creation date
set theFile to (item 1 of reverse of result) as alias
set newName to lang & "-" & size & " .png"
set name of theFile to newName
end tell
--iPad
if size as string is equal to ipad then
tell application "Automator" to activate
tell application "System Events"
tell process "Simulator"
tell menu bar 1
tell menu "Hardware"
tell menu item "Orientation"
tell menu "Orientation"
click menu item "Landscape Right"
end tell
end tell
end tell
delay 2
tell menu "File"
click menu item "New Screen Shot"
end tell
tell application "Finder"
set the source_folder to (path to desktop folder) as alias
sort (get files of source_folder) by creation date
set theFile to (item 1 of reverse of result) as alias
set newName to lang & "-" & size & "-landscape" & " .png"
set name of theFile to newName
end tell
tell menu "Hardware"
tell menu item "Orientation"
tell menu "Orientation"
click menu item "Portrait"
end tell
end tell
end tell
end tell
end tell
end tell
end if
end repeat
end repeat
return input
end run