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

查看:23
本文介绍了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

告诉应用程序查找器"打开 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 Scripts 的系统事件按编辑菜单下的复制.

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天全站免登陆