automator - Passing Variables to another Applescript Application -


i have found few things on how run applescript application not on giving input. on applescript site found this:

tell application "nonstayopen"   launch   stringtest("some example text.") end tell 

which solution, rap script in handler , pass variable. not matter can not handler activate.

ideal situation run script contains following:

tell application id "com.apple.testhandlerapp"   testhandler("hi") --or if can open(somevar) work end tell 

which activates application testhandlerapp containing script:

on testhandler(somevar)     set contenttext somevar string     display dialog contenttext end testhandler 

giving me dialog saying "hi". reason being want put first bit of code automator runs complex application takes text input. right "connection invalid." if didn't need input seems using activate works fine.

there's 2 ways can think of.

1) create "testhandlerapp.app" following code. saved mine on desktop. you'll notice has "on run" handler accepts argument list runs testhandler(). try block of code prevents error if launch app yourself. in case there no argument list passed , code errors try block prevents that.

note: method work if save plain script instead of application.

on run arglist     try         class of arglist     on error         set arglist {"no arguments passed!"}     end try      testhandler(item 1 of arglist) end run  on testhandler(somevar)     set contenttext somevar string     display dialog contenttext end testhandler 

then call applescript use "run script" command follows.

set apppath (path desktop text) & "testhandlerapp.app" run script file apppath parameters {"hi"} 

you can call command line this...

osascript /path/to/script arg1 arg2 

2) create "testhandlerapp.app" following code. save "stay open" applescript application checking "stay open" checkbox in save window.

on run end run  on testhandler(somevar)     set contenttext somevar string     display dialog contenttext end testhandler 

then call applescript use this...

tell application "testhandlerapp"     testhandler("hi")     quit end tell 

good luck!


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -