Xcode从其他应用程序/命令行/ Apple脚本运行

时间:2017-09-01 13:01:59

标签: xcode bash applescript appcode app-code

是否可以在后台安装Xcode,但是可以通过脚本编译并运行当前项目?

我主要使用AppCode进行开发,但想通过热键从Xcode运行。 AppCode没有正确显示编译进度条(第二个屏幕上的Xcode可以),AppCode的调试功能也不像Xcode那样先进。否则AppCode会更快更好。

1 个答案:

答案 0 :(得分:1)

可以从AppleScript开始,这是一个示例脚本(在 Sierra Xcode版本8.3.3 上测试):

tell application "Xcode"
    tell active workspace document to if exists then
        repeat until (loaded) -- Whether the workspace document has finished loading after being opened
            delay 1
        end repeat
        run -- Invoke the "run" scheme action
    end if
end tell

要在特定设备上运行:我没有要测试的设备,但是我使用模拟器,试试这个脚本:

tell application "Xcode"
    tell active workspace document to if exists then
        repeat until (loaded) -- Whether the workspace document has finished loading after being opened
            delay 1
        end repeat
        --**** run on a specific device ****
        set active run destination to run destination "iPad Pro (12.9 inch)" -- *** change it to the name of your device  ***

        set schAction to run -- Invoke the "run" scheme action
        repeat while (get status of schAction) is in {not yet started, running} -- exit the loop when the status is (‌cancelled, failed, ‌error occurred or ‌succeeded), so I press the stop button in Xcode, or I delete the application in the simulator or I quit the simulator.
            delay 3
        end repeat

        --**** run on another specific device ****
        set active run destination to run destination "iPhone 7" -- *** change it to the name of your device  ***
        run
    end if
end tell