How Can I Open AppleScript App with Arguments How Can I Open AppleScript App with Arguments bash bash

How Can I Open AppleScript App with Arguments


Why doesn't anyone mention quoted form of? When you want to send arbitrary data as an argument to an application you should use quoted form of. When quotes, spaces and other special characters are in the given path the command will break down in de previous examples.

on run argv    tell application "Terminal"        do script "./myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"    end tellend run

Since you mentioned you're new to AppleScript does it have to run in the Terminal.app or is a shell enough? AppleScript has the command do shell script which opens a shell, execute the text and return the stdout back to you.

on run argv   do shell shell script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " 2>&1"end run

Last but not least. If you don't want the output of the scan program and don't want AppleScript to wait until it's finished you can use

on run argv   do script "/path/to/myscanprogram " & quoted form of (item 1 of argv) & " &>/dev/null &"end run


Wondering why you're using your Terminal to address an AppleScript that uses the Terminal again, but maybe I just don't know your circumstances...

Applescript:

on run argv    tell application "Terminal"        do script "./myscanprogram " & (item 1 of argv) & " 2>&1"    end tellend run

Call from osascript inside your Terminal:

osascript pathToYourScript.scpt myargument