Open travisjeffery opened 13 years ago
I also want to know how to use peepopen with Xcode 4!
+1
I've worked around this by adding a Service using Automator. The last time I wrote AppleScript was with HyperCard 15 years ago, so this is ugly, but it's working for me.
To set it up, open Automator and choose to create a Service. Find Run AppleScript in the list of Actions and double-click it to add it to your service. There's a dropdown above where the AppleScript goes that says "Service receives selected text" -- change this to "no input" and set the application drop down to point to Xcode (probably in /Developer/Applications).
Now replace the default script with the following:
on run {input, parameters}
tell application id "com.apple.dt.Xcode"
set my_work_space to active workspace document
set my_projects to projects of my_work_space
set my_project to item 1 of my_projects
do shell script "open -a PeepOpen " & path of my_project & "/.."
end tell
end run
Save the Service (I just called it PeepOpen) and go to the Keyboard section of System Preferences. Under Keyboard Shortcuts, you'll see Services listed in the left pane. Select it and you'll find your PeepOpen service at the bottom. If you click to the right of the Service name you can set a keyboard shortcut that will open PeepOpen for the current project.
@mcobrien Thanks for the script!
In principal it works but my Xcode projects were generated with CMake and the build directory (which contains the Xcode project) is outside of the source directory. So I modified the script to look for the first folder in the project which in the CMake case points to the source directory:
tell application "Xcode"
tell front project
-- The project root
set root_group to root group
-- The first folder in the project root
-- (Sources folder in CMake generated projects)
set first_item to first item reference of root_group
-- Get the file path
set my_sources_path to full path of first_item
-- Open with peepopen
do shell script "open \"peepopen://" & my_sources_path & "?editor=Xcode\""
end tell
end tell
@mcobrien Your solution worked for me, but instead of adding the keyboard shortcut to the service PeepOpen, I had to add it under Application Shortcuts and specify the name of the service in Menu Title as PeepOpen. Not sure why exactly, but hey it works now. Thanks!
great ! but I got "no service Apply" in Xcode 4 Menu.. x_x need some help
No need to use automator or keyboard shortcuts in system prefs, it's built in to Xcode 4 itself.
First, create a apple script similar to what has been posted above. I used this:
#!/usr/bin/osascript
tell application "Xcode"
tell first project
set dir to (get project directory)
do shell script ("open -a PeepOpen '" & dir & "'")
end tell
end tell
save it to a file somewhere to your liking (e.g. ~/bin/xcode-peepopen.scpt). After that
chmod +x ~/bin/xcode-peepopen.scpt # Or whatever you named the file to.
Et voilá!
PS. The reason it's an Apple script instead of a shell script as per the help in peep open, is because the environment variable needed (PBXFilePath) doesn't exist in Xcode 4. It's in Xcode 3 though.
PS2. I've used this successfully in Xcode 4.3.2.
@wailqill that's awesome and works perfectly! So far it seems a quicker than the services approach as well, which is great.
I had to chmod +x the script to be able to select it in Xcode. Works great!
Sorry, I forgot to mention that. Added it to my comment. Thank you @bradjasper.
If you change the AppleScript slightly to:
#!/usr/bin/osascript
tell application "Xcode"
tell first project
set dir to (get project directory)
set script_command to "open peepopen://" & dir & "?editor=Xcode"
do shell script script_command
end tell
end tell
PeepOpen will always open the file in Xcode, regardless of the setting you've chosen in its preferences.
Hello everyone,
I am trying wailqill solution but I am getting an error:
Failed to launch script /Users/dathinaios/Documents/4_Archive/Data/My_scripts_and_Apps/xcode-peepopen.scpt: The operation couldn’t be completed. Bad file descriptor
Any ideas why?
I wrote an Xcode plugin to fix this. https://github.com/enriquez/PeepOpen-Xcode-4-Plugin
The current installation method and documentation needs to be fixed/updated.