Skip to content

Instantly share code, notes, and snippets.

@JimRoepcke
Created April 13, 2011 19:50
Show Gist options
  • Save JimRoepcke/918268 to your computer and use it in GitHub Desktop.
Save JimRoepcke/918268 to your computer and use it in GitHub Desktop.
Make an Automator service that receives text with a Run Applescript command
-- select @"foo", activate this service
-- @"foo" is replaced with kFoo and
-- the clipboard contains the variable
-- declaration for your .h/.m files
-- http://discussions.apple.com/message.jspa?messageID=2900758
on getString(testChar, theString, searchList, replaceList)
set {oldDelims, AppleScript's text item delimiters} to ¬
{AppleScript's text item delimiters, {testChar}}
set charOffset to (length of (text item 1 of searchList)) + 1
set textItems to text items of theString
set theChar to (character charOffset of replaceList)
set AppleScript's text item delimiters to {theChar}
set theString to textItems as string
set AppleScript's text item delimiters to oldDelims
return theString
end getString
-- http://discussions.apple.com/message.jspa?messageID=2900758
on uppercaseString(theString)
set upperCaseChars to "ABCDEFGHIJKLMNOPQRSTUVWXYZÆŒØ∏ÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜŸ"
set lowerCaseChars to "abcdefghijklmnopqrstuvwxyzæœøπáàâäãåçéèêëíìîïñóòôöõúùûüÿ"
considering case
repeat with i from 1 to theString's length
set testChar to character i of theString
if testChar is in lowerCaseChars then
set theString to getString(testChar, theString, lowerCaseChars, upperCaseChars)
end if
end repeat
end considering
return theString
end uppercaseString
on run {input, parameters}
set s to item 1 of input
set len to the length of s
set theKey to characters 3 through (len - 1) of s as string
set len to the length of theKey
set v to "k" & uppercaseString(character 1 of theKey) & (characters 2 through len of theKey as string) & "Key"
-- display dialog "Variable Name" default answer v
-- set v to the text returned of the result
set h to "extern NSString * const " & v & ";\n"
set m to "NSString * const " & v & " = " & s & ";\n"
set the clipboard to m & h
return v
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment