Created
June 8, 2011 14:01
-
-
Save idoru/1014467 to your computer and use it in GitHub Desktop.
Applescript for an Automator service that switches between specs and implementations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on run {input, parameters} | |
tell application "Xcode" | |
set my_workspace to active workspace document | |
set workspace_projects to projects of my_workspace | |
set currentFullPath to "" | |
set projectDir to "" | |
set reverseDocumentList to (reverse of (source documents as list)) | |
repeat with currentSourceDocument in reverseDocumentList | |
repeat with currentProject in workspace_projects | |
set projectDir to project directory of currentProject | |
if path of currentSourceDocument starts with projectDir then | |
set currentFullPath to path of currentSourceDocument | |
exit repeat | |
end if | |
end repeat | |
if length of currentFullPath > 1 then exit repeat | |
end repeat | |
try | |
set original_delimiters to AppleScript's text item delimiters | |
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 original_delimiters | |
on error | |
set AppleScript's text item delimiters to original_delimiters | |
end try | |
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 filenameToFind to (characters 1 thru (prefixLen - 4) of filePrefix) as string | |
else | |
set filenameToFind to filePrefix & "Spec" | |
end if | |
set filenameToFind to filenameToFind & ".m" | |
set foundFile to do shell script "find " & projectDir & " -name " & filenameToFind | |
if length of foundFile > 1 then open foundFile | |
end tell | |
return input | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment