AppleScript创建Xcode目标的副本 [英] AppleScript to create a duplicate of Xcode target

查看:201
本文介绍了AppleScript创建Xcode目标的副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以使用AppleScript创建目标的副本.我正在使用以下代码,但显示错误:Xcode出现错误:无法复制目标.

Is there any way to create a duplicate of target using AppleScript. I am using below code but it shows Error : Xcode got an error: Targets can not be copied.

tell application "Xcode"
tell active workspace document
    set firstProject to (get first project)
    set firstTarget to (get second target of firstProject)
    tell application "Xcode" to duplicate firstTarget
end tell
end tell

上面的脚本适用于当前在Xcode中打开的项目.

above scripts is for the project that is currently open in Xcode.

我有不同的方法来实现它,但没有弄清楚它如何工作.

I have different approach to achieve it but not getting how to make it work.

  1. 打开一个Xcode项目

  1. Open an Xcode project

告诉应用程序"Finder" 打开POSIX文件"/Users/TestUser/Desktop/CoBranding/source/tet/test.xcodeproj" 结束告诉

tell application "Finder" open POSIX file "/Users/TestUser/Desktop/CoBranding/source/tet/test.xcodeproj" end tell

选择一个特定的目标并选择它(保持关注)

Choose a particular target and and select it (keep focus on it)

告诉应用程序"Xcode" 告诉活动的工作区文档 将firstProject设置为(获取第一个项目) 将projectDirectory设置为(获取firstProject的项目目录)
结束告诉 结束告诉

tell application "Xcode" tell active workspace document set firstProject to (get first project) set projectDirectory to (get project directory of firstProject)
end tell end tell

现在使用Apple Script的系统事件在编辑"菜单下按复制".

Now press Duplicate under Edit menu using system events of Apple Scripts.

推荐答案

您可以使用此脚本

tell application "Xcode"
activate
delay 3
tell active workspace document
    set my_project to (get first project)
    tell my_project

        tell application "System Events"
            keystroke "d" using {command down}
            delay 0.5
            tell application process "Xcode"
                delay 1.0E-3

                click button "Duplicate Only" of window 1


            end tell

        end tell

    end tell
end tell
end tell

您的xcode项目只需要一件事就可以激活:)祝您好运

only one thing needed your xcode project should be active :) Good Luck

这篇关于AppleScript创建Xcode目标的副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆