Thanks to much help here, I’ve figured out how to write a script that runs different scripts depending on whether or not Word is installed - by running one of two different application bundles inside the main bundle. The one problem I can’t figure out is how to pass a list of dropped files from the main bundle to the ones inside. This doesn’t work:
on open fileList
set wordInstalled to 0
try
tell application "Finder"
set wordID to get application file id "com.microsoft.Word"
set wordInstalled to 1
end tell
end try
set appPath to (path to me as text) & "Contents:Resources:Apps:"
if wordInstalled is 1 then
set myScript to alias (appPath & "WPWordConverter.app")
else
set myScript to alias (appPath & "WPOpenConverter.app")
end if
run script myScript with parameters {fileList} -- this doesn't work
tell me to quit
end open
on run
set wordInstalled to 0
try
tell application "Finder"
set wordID to get application file id "com.microsoft.Word"
set wordInstalled to 1
end tell
end try
set appPath to (path to me as text) & "Contents:Resources:Apps:"
if wordInstalled is 1 then
set myScript to alias (appPath & "WPWordConverter.app")
else
set myScript to alias (appPath & "WPOpenConverter.app")
end if
run script myScript
tell me to quit
end run
Can anyone suggest a syntax that might in fact work? Is this possible at all?
Thanks for any help.
I would write the list of paths in a temporary file.
The called script would check if the parameters file exists. If it is it would read it to get the paths (open case), if it doesn’t exists it would work without the paths (run case).
For my use I would write a simple text file in the Preferences folder.
To be sure that all behaves as wanted, I would add code deleting a possible parameters file in the run handler.
on open fileList
my common(fileList)
end open
on run
my common({})
end run
on common(fileList)
set wordInstalled to 0
try
tell application "Finder"
set wordID to get application file id "com.microsoft.Word"
set wordInstalled to 1
end tell
end try
set appPath to (path to me as text) & "Contents:Resources:Apps:"
if wordInstalled is 1 then
set myScript to alias (appPath & "WPWordConverter.app")
else
set myScript to alias (appPath & "WPOpenConverter.app")
end if
if fileFist is {} then
--delete parameters file
else
-- write the paths in a parameters file
end if
run script myScript
tell me to quit
end common
Yvan KOENIG running El Capitan 10.11.6 in French (VALLAURIS, France) samedi 13 aout 2016 11:06:05
Hi.
Do your other scripts have the appropriate parameter-receiving arrangements?
on run {fileList}
repeat with thisFile in fileList
-- Blah blah blah.
end repeat
end run
Thank you Nigel,
The problem here was User Stupidity. I had the parameter-receiving arrangement in the on open block (as if I were dropping a file on the other script). Now it’s solved. Thank you!