Xcode 4 : Can I get a path to the currently active file via AppleScript?

為{幸葍}努か 提交于 2020-01-13 09:15:32

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/10341327/xcode-4-can-i-get-a-path-to-the-currently-active-file-via-applescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!