Reputation: 6062
Is it possible to set a keyboard shortcut (or maybe add some menu item somewhere) to open currently edited file in external editor?
(Obviously I may do [ (right click in file tree → Show in Finder) / (right click in window title → select containing directory) ] → right click on file → Open With → "the app" — but it's too much steps.)
Upvotes: 4
Views: 2888
Reputation: 24793
I really liked the solution that Fjölnir made, so to expand on how to do that.
External
If you are using MacVim for this, you can improve the load time for the external editor by configuring it to stay running after the last window closes.
Now when I press ⌥E
the window pops open, I make my change, :q
, and focus returns to Xcode.
Upvotes: 2
Reputation: 5262
Because I use tabs, I was eager for a solution that wouldn't open a document from the first tab. I ended up with following:
Note: If Assistant editor is opened, the file from the Standard Editor (on the left side) is opened regardless which editor is active, but for me it's better than the first tab.
on run {input, parameters}
set current_document_path to ""
tell application "Xcode"
set last_word_in_main_window to (word -1 of (get name of window 1))
if (last_word_in_main_window is "Edited") then
display notification "Please save the current document and try again"
-- eventually we could automatically save the document when this becomes annoying
else
set current_document to document 1 whose name ends with last_word_in_main_window
set current_document_path to path of current_document
end if
end tell
tell application "MacVim"
if (current_document_path is not "") then
activate
open current_document_path
end if
end tell
return input
end run
Upvotes: 3
Reputation: 979
A better solution is to add a keyboard shortcut directly in the keyboard preferences pane:
Upvotes: 3
Reputation: 6062
Huh, I've found it.
Paste this code (replace MacVim with your editor)
tell application "Xcode"
set current_document to last source document
set current_document_path to path of current_document
end tell
tell application "MacVim"
activate
open current_document_path
end tell
Save workflow.
I've borrowed AppleScript code from this project: Uncrustify Automator Services for Xcode 4.
Upvotes: 11