Automatorは、AppleScriptでmacOSアプリケーションを管理します

ある素晴らしい夜、同僚と私はAppStoreで小さなアプリケーションを公開しました。アプリケーションの公開はかなり長いプロセスであり、多くの段階で構成されています。ステージの1つは、アプリストアの画像を準備することです。タスクは一見簡単です。シミュレーターでアプリケーションを起動し、アプリケーションのスクリーンショットを撮りますが、アプリケーションの5つの異なる状態のデモンストレーションを備えた、いくつかのサイズの6つの言語の画面が必要です。1時間は、コーヒーを飲みながら一般的な話題について話し合いながら、手で写真を撮るだけで管理できました。しかし、私たちはプログラマーであり、それを手作業で行う方法ではありません。プロセスを自動化する必要があります。私たちは決してそれをしませんでしたが、私たちはそれをしました。macOSアプリケーションをプログラムで管理するのがいかに簡単かを学びました。そして、XCodeアプリとSimulatorアプリを実行するAppleScriptを作成しました。





演出

. 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.





もちろん、ファイルのコピーを自動化することもできますが、そこで停止しました。





結果

約1時間で120枚すべての写真を手で作成する代わりに、プログラムとAppleScript言語を習得するのに3時間費やして、Automatorの使用方法を学びました。スクリプトを使用すると、最小限の操作で1分あたり120枚の写真を生成できました。長い時間の投資にもかかわらず、私たちは満足しました。私たちの経験が他の人々や他の仕事に役立つことを願っています。





そして、ここに完全なコードがあります:





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
      
      






All Articles