Skip to content

Instantly share code, notes, and snippets.

@idoru
Created November 17, 2010 05:36
Show Gist options
  • Save idoru/703035 to your computer and use it in GitHub Desktop.
Save idoru/703035 to your computer and use it in GitHub Desktop.
[Not compatible with XCode 4] Ever wanted to switch between Cedar specs and your implementation with a single keystroke? Well, there's a user script for that!
(*
SwapBetweenSpec.scpt
Get into the BDD groove with this Xcode user script which quickly toggles between your implementation (or header)
and its Cedar Spec. Bind it to your favorite shortcut key and enjoy the cycle.
Be sure to add this User Script to Xcode as an Applescript, not a shell script:
1. Paste the contents of the gist into ~/Library/Application Support/Developer/Shared/Xcode/User Scripts/SwapBetweenSpec.scpt
2. When adding to script in the "Edit User Scripts" window of Xcode, choose "Add Script File..." and not "New Shell Script" and then choose the file from (1)
3. Set Input to "No Input"
4. Set Directory to "Selection"
5. Set Output to "Discard Output"
6. Set Errors to "Ignore Output"
7. Bind to a key of your choice - I like Cmd + Opt + Down
*)
using terms from application "Xcode"
set currentProject to project of active project document of application "Xcode"
set currentFullPath to associated file name of first window of application "Xcode" as string
set AppleScript's text item delimiters to "/"
set currentFileName to last text item of currentFullPath as string
set AppleScript's text item delimiters to "."
set filePrefixItems to text items of currentFileName as list
set AppleScript's text item delimiters to {""}
set filePrefix to ""
repeat with textItemNumber from 1 to ((count of filePrefixItems) - 1)
if textItemNumber > 1 then
set filePrefix to filePrefix & "."
end if
set filePrefix to filePrefix & item textItemNumber of filePrefixItems
end repeat
set prefixLen to count of filePrefix
set specSuffix to (characters (prefixLen - 3) thru (prefixLen) of filePrefix) as string
if (specSuffix = "Spec") then
set searchPrefix to (characters 1 thru (prefixLen - 4) of filePrefix) as string
else
set searchPrefix to filePrefix & "Spec"
end if
set searchPrefix to searchPrefix & ".m"
repeat with fileRef in file references of currentProject
if (path of fileRef) = searchPrefix then
set found to fileRef
tell application "Xcode"
open (full path of fileRef as string)
end tell
end if
end repeat
end using terms from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment