How can I convert the input __NSArrayM into an AppleScript list in an Automator Action project? -


automator action

i making custom automator action manipulating text input. tested input see class , result __nsarraym. means need somehow convert input list applescript can understand—and string. need isolate string , convert same object output.

summary:

  • convert __nsarraym input applescript list object
  • convert applescript list object __nsarraym output

i automator this: enter image description here

coding attempt in xcode

my attempt @ coding looks like:

script change_case     property parent : class "ambundleaction"     property menuchoices : {"title case","upper case","lower case","toggle case"}     property menuselection : 0     on runwithinput_fromaction_error_(input, anaction, errorref)         set inputclass class of input -- debugging          set menusel menuselection         if menusel 0 -- title case             display dialog menusel string         end if          tell class "nsarray" of current application set inputvalues arraywithobjects_(input)         log inputvalues -- debugging     end runwithinput_fromaction_error_ end script 

final code update

i thought post final code automator action completeness. key step make input , output com.apple.cocoa.stringas shown in picture below.

script change_case     property parent : class "ambundleaction"     property menuchoices : {"title case","upper case","lower case","toggle case"}     property menuselection : missing value     property array : class "nsarray"      on runwithinput_fromaction_error_(input, anaction, errorref)         set inputvalues input list         set thestring item 1 of inputvalues          if (menuselection string) "missing value"             set menuselection 0         end if         set menuselection menuselection integer          if menuselection 0 -- title case             --display dialog "title case, menu selection id: " & menuselection string             set mycode "import sys; print sys.argv[1].title()"             set myscript "/usr/bin/python -c " & mycode's quoted form & " " & quoted form of thestring             set output (do shell script myscript) string         end if         if menuselection 1 -- upper case             --display dialog "upper case, menu selection id: " & menuselection string             set mycode "import sys; print sys.argv[1].upper()"             set myscript "/usr/bin/python -c " & mycode's quoted form & " " & quoted form of thestring             set output (do shell script myscript) string         end if         if menuselection 2 -- lower case             --display dialog "lower case, menu selection id: " & menuselection string             set mycode "import sys; print sys.argv[1].lower()"             set myscript "/usr/bin/python -c " & mycode's quoted form & " " & quoted form of thestring             set output (do shell script myscript) string         end if         if menuselection 3 -- toggle case             --display dialog "swap case, menu selection id: " & menuselection string             set mycode "import sys; print sys.argv[1].swapcase()"             set myscript "/usr/bin/python -c " & mycode's quoted form & " " & quoted form of thestring             set output (do shell script myscript) string         end if         return output     end runwithinput_fromaction_error_ end script 

inputautomator

is goal of script take array of text strings, , change case based upon menuselection?

you can coerce passed array list:

set inputvalues input list 

is planned receive single text input? go target/general, input , output options: com.apple.applescript.text-object or com.apple.cocoa.string these class of array items passed.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -