0

I need an AppleScript that opens an Xcode project and duplicates its last target.

I've found some answers here and there but none of them seem to work (at least with Xcode 9.1).

I've tried this:

do shell script "open <myproject>"
tell application "Xcode"
    tell active workspace document
        tell first project
            duplicate last target
        end tell
    end tell
end tell

But it fails with:

execution error: Error in Xcode: Can not set last target of project 1 of active workspace document to last target of project 1 of active workspace document. (-1006)

How would you do that?

user3439894
  • 7,266
  • 3
  • 17
  • 28
sdabet
  • 18,360
  • 11
  • 89
  • 158

1 Answers1

0

Apple has obviously removed duplicate from the commands in the Standard Suite. That means the target class does not respond to duplicate.

Unfortunately the UI elements in the project navigator have no actions so you can't select the target and press ⌘D with GUI scripting either.

So the only way to duplicate a target programmatically is a third party solution like Keyboard Maestro which is able to perform a mouse click on a specific location to simulate select the project -> select the target -> Press ⌘D

vadian
  • 274,689
  • 30
  • 353
  • 361