0

I'm building a "Wizard" of sorts that uses Automator and some Appliescript, and at the end I would like it to generate an "Automator Application" that does things when launched, that are based on the inputs from the wizard.

Is this even possible? Can one Automator workflow, actually generate an application from the results? I know software can create software, but is this possible within Automator's capabilities?

EDIT: As noted in the comments below the post, osacompile seems like it might get me where I want to go, but now I have a new problem with that.

Here's a screenshot of my automator steps:

Automator routine

Here's the code of the erroring module (Send iMessage):

on run {input, parameters}
    
    set sms_address to item 1 of input
    set email_address to item 2 of input
    set sms_content to item 3 of input
    set email_subject to item 4 of input
    set email_body to item 5 of input
    
    set savePath to (path to desktop as text) & "test.scpt"
    
    set code to "osacompile -e 'tell application \"Messages\"' -e ' 
    set imessageservice to 1st service whose service type = iMessage' -e '
    set iMessageBuddy to buddy " & sms_address & " of imessageservice' -e '
    send " & sms_content & " to iMessageBuddy' -e '
    end tell' -o " & quoted form of POSIX path of savePath
    
    do shell script code
    
    return input
end run

Note that the lines are broken up that way because it was the only approach I could find where I didn't get any errors just because of adding line breaks (I can put this code all on one line and get the identical error)

Here's the error I receive:

osacompile error message

I haven't been able to figure out what the problem is here but it seems like I'm not passing the variables in the way a bash script expects. Have tried a bunch of other approaches and nothing has worked any better, but this is the one that seems the most sensible to me, knowing how I would normally pass variables into a script.

EDIT 2: To simplify further, here is the standalone code I'm current debugging in AppleScript Editor and without any line breaks to not confuse the issue:

set sms_address to "person@gmail.com"
set sms_content to "sms content"

set savePath to (path to desktop as text) & "test.scpt"

set code to "osacompile -e 'tell application \"Messages\"' -e ' set imessageservice to 1st service whose service type = iMessage' -e 'set iMessageBuddy to buddy " & sms_address & " of imessageservice' -e 'send " & sms_content & " to iMessageBuddy' -e 'end tell' -o " & quoted form of POSIX path of savePath

do shell script code
14
  • I'm not aware of a way to build an Automator application, but the osacompile shell utility can be used to create applets. What kind of "inputs" are you trying to use? – red_menace Jul 15 '20 at 2:36
  • I'm trying to create a simple program so I can schedule text messages and emails to myself to remind me of certain things. I want to prompt for things like the phone number to use, email subject line and body, etc. and then compile that into an application that will execute the javascripts to send a text or create an email using those previously inputted values. Once there is an application, then I can create a calendar event that will trigger the app at the desired time. For now compiling the app is my big obstacle. – JVC Jul 15 '20 at 3:02
  • It's possible I've got a lead on the answer from stackoverflow.com/questions/25817752/… and thanks to you mentioning osacompile. If I get something that works, I'll answer the question assuming nobody else has by then. – JVC Jul 15 '20 at 3:55
  • So this is showing great promise, but I can't manage to pass a variable (from input) into the shell script without throwing an error. Is there some special method for passing a variable in? I tried using double quotes to drop out of the osacompile and back again, but no go. What am I missing here... seems like this should be simple. I'm very close to an elegant and complete answer. – JVC Jul 15 '20 at 4:53
  • Hard to tell without seeing some code, but note that the input argument is a list, so you would need to coerce, repeat through it, or get an item from it. – red_menace Jul 15 '20 at 11:07
0

So from the edits to my post, I was on the right track. But I forgot that the final script needs to have quotes around the content being passed in! This is the code snippet that ultimately worked:

set sms_address to "sms_address"
set sms_body to "sms_body"
set filename to "filename"
set savePath to (path to desktop as text) & filename & ".scpt"

set code to "osacompile -e '
tell application \"Messages\" 
    set imessageservice to 1st service whose service type = iMessage 
    set iMessageBuddy to buddy \"sms_address\" of imessageservice 
    send \"sms_body\" to iMessageBuddy
end tell' -o " & quoted form of POSIX path of savePath

do shell script code

So I was on the right path all along, just needed to excape those double quotes.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .