7

I am trying to write a custom xcode4 behavior to check out the current active file with Perforce. I know I can write a custom behavior to run when hit a key (e.g., F1) I'd like that custom behavior to launch an AppleScript (or any kind of script for that matter) that discerns the currently "active" source document in Xcode, get its path, and attempt to check it out via Perforce.

As far as I can tell AppleScript is the best way to get to the target document as it can navigate the Xcode DOM easily. Given that, the DOM itself is a maze.

Can this be done?

fbrereto
  • 35,429
  • 19
  • 126
  • 178
  • 2
    I answered this [here][1] (SO Link). This had been bugging me for months. [1]: http://stackoverflow.com/questions/5532334/perforce-checkout-macro-for-xcode4 – Mark May 21 '12 at 17:07

1 Answers1

7

Yes.

tell application "Xcode"
    set CurrentActiveDocument to document 1 whose name ends with (word -1 of (get name of   window 1))
    set WhatYouWant to path of CurrentActiveDocument
end tell
BB9z
  • 2,432
  • 1
  • 30
  • 36
  • 1
    This works EXCEPT if you are using the Assistant editor - then you end up with whatever happens to be in the Standard Editor. – Lloyd Sargent Jul 28 '13 at 21:56