1
votes

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

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. Open an Xcode project

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

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

    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

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

1

1 Answers

1
votes

You can use this script

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

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