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.)
Huh, I've found it.
Start Automator.app.
Select "Service".
Drag-n-drop "Run AppleScript" to workflow.
Set "service receives" to "no input", and application is Xcode.
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.
In System Preferences → Keyboard → Keyboard Shortcuts → Services → General, assign a shortcut.
You're done!
I've borrowed AppleScript code from this project: Uncrustify Automator Services for Xcode 4.
A better solution is to add a keyboard shortcut directly in the keyboard preferences pane:
open "System Preferences" → "Keyboard" → "Keyboard Shortcuts" → "Application Shortcuts"
click on the "+" plus sign
select "XCode" as Application and type "Open with External Editor" as Menu Title
set your shourcut (I'm using ⇧⌃E)
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
I really liked the solution that Fjölnir made, so to expand on how to do that.
Choose the Menu: "Xcode" -> "Preferences..."
Click the "Key Bindings" Tab on the Preferences Window
In the "Filter" search box enter External
Double click on the "Key" column next to the "Open with External Editor (File Menu)" command.
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.
Choose the Menu: "MacVim" -> "Preferences..."
In the "General" tab set "After last window closes" to "Hide MacVim"
Now when I press ⌥E the window pops open, I make my change, :q, and focus returns to Xcode.
Related
I am new to textwrangler and I am trying to figure out how to have a shortcut for commenting out blocks of haskell code. The available Un/Comment Block option from the menu doesn't seem to do anything.
I've used Prefix/suffix lines but that is just too awkward. Does anyone have any suggestions?
Thanks
I'm assuming you're using TextWrangler on OS X.
When you're running TextWrangler you should see a little scroll in the menu bar (the AppleScript button). Click it. Then choose the 'Open Script Editor' option. Go to your Desktop folder and click 'New Document'. Name the file something like 'comment_script'. Type the following text into the editor window that appears:
tell application "TextWrangler"
set my_selection to selection
set my_selection to "{-\n" & my_selection & "\n-}"
set selection to my_selection
end tell
Save it and quit the editor.
Once you're done with that, copy the comment_script file to the folder ~/Library/Application\ Support/TextWrangler/Scripts
Now you'll find comment_script in the script menu (the one with the scroll). Select some text in TextWrangler and then click on comment_script in the script menu to comment the selection.
This question concerns applescript syntax. What does applescript call a drop down menu? And what does applescript call an item on a drop down menu?
This works via 'System Events'. Let's say you want to click 'open file...' from the 'file' menu.
tell application "System Events" to tell process "Finder"
click menu item "Open file..." of menu 1 of menu bar item "File" of menu bar 1
end tell
I think the author was looking for the term "pop up button" or "combo box".
I want to change the key binding of "Go to File" of textmate from it's default one Cmd + T to option + cmd + n. How to do that?
Head into System Preferences → Keyboard → Shortcuts → App Shortcuts.
Add a new Application (Textmate) and the Menu Title should be 'Go to File..."
I tried just using 'Go to File' but found out the actual title requires the additional '...'
Go to System Preferences → Keyboard → Shortcuts.
Click App Shortcuts and then the plus button to create a new entry.
Select TextMate as application, set menu title to Go to File… (including the ellipsis) and then pick your desired key equivalent.
Say you have File.m showing in the blue area above.
I want File.m to open in a new separate window.
How to do this??
Note that - of course - IF you have the ProjectNavigator showing and IF you can see the filename "File.m", then double-click on the filename and it will open in a new window.
What I want to do is open ANOTHER copy of the "CURRENT" file (the one in the primaryEditor) in a NEW WINDOW - without touching the ProjectNavigator.
Any ideas? Cheers
Note that ... (an excellent page here)
http://realmacsoftware.com/blog/xcode-4-s-less-obvious-shortcuts
if you click on whatever file is in the current primaryEditor, then shift option apple comma that will indeed open the following "freaky little-known Xcode popup" ...
you can then, indeed, choose to open a new window. (So to be clear, that is exactly what I want to do.)
So, I want to be able to do that in one step. Cheers!
In XCode's Preferences you can change the following:
And then right-click within the primary editor and click "Open in Separate Window"
Edit:
Instead of right clicking in the primary editor you can simply type command+option+, (comma)
Open the file what you want to open in the NEW window.
Command + Shift + t
Open the file what you want to open in the separated window.
Command + Option + ,
I wrote a new automator service that does the following steps in Xcode:
Execute the default shortcut for the "Open in..." menu item (Command-O)
(if this isn't your current "Open in" shortcut, the workflow will not work. If you still want to test it, just changed your default shortcut :) )
Go all the way to the left in the weird "Open in" view
hit Enter
Current file opened in new window
The only thing you need to do is install the service on osx and map a shortcut to it.
Here a download to the service:
https://www.dropbox.com/s/486t2iz17o0l9dh/Open-New-Window.zip
INSTALL INSTRUCTIONS
1.Place Service file in folder ~/Library/Services
2. Open "System preferences"
3. > Keyboard
4. > Tab "ShortCuts" > "Service" > "General"
5. > Set your own shortcut for the service
6. Go to XCode and test the service by using your very own shortcut
Tested on OS X Mavericks, Xcode 5.0.1
In XCode 4 you can have a split window via View -> Show Assistant Editor. Then choose the same file which you have already opened in the Primary editor by the small right arrows on top of Assistant Editor.
Thanks
in the ProjectNavigator. If you see the file name: Double click on the file name. It will open in a new window.
I'd like to activate a particular window of a nonscriptable app, and decided to just use XCode as an exemplar. So here's one setup:
Launch Xcode, open some project (I opened Son of Grab)
Double click a source file to open a source window (Controller.m in my case)
Select Window | Organizer to open the Organizer window
at this point you'll have three Xcode windows, a project (main) one, the Organizer, and a source window.
Focus the source (again Controller.m in my case) window.
Try to focus the "Organizer - Documentation" window in a script; my simpleminded approach was:
tell application "Xcode"
activate window "Organizer - Documentation"
end tell
After this runs, the source window that was focused before I ran the script will again be focused - but not the Organizer window.
What am I missing? Thanks to all!
The activate command brings the application to the front. Each application will have its own terminology for dealing with its documents, so you would need to look at the scripting dictionary. In Xcode, it looks like you can get what you want by setting the index of the document (usually the front to back ordering), for example, using your snippet:
tell application "Xcode"
activate
set index of window "Organizer - Documentation" to 1
end tell