I have a script that I have written that works perfectly when run from Script Editor. For ease of use, I am trying to convert it to a droplet.
When, I run it as a droplet, the script fails telling me that a variable doesn’t exist. The variable is most certainly defined as global, has a value attributed to it, and has been referenced in the main part of the script. It fails on the first occurrence in a handler.
Why would the global be passed when run as a script, but not as a droplet?
on open theItem
global personalization1List, personalization2List, personalization3List, personalization4List, personalization5List, vendorItemList, nr
tell application "Microsoft Excel"
activate
-- open the data file.
set theData to theItem
open theData
set lastCell to first row index of (find column 2 what "" look in values look at whole)
set vendorItemList to the value of the range ("ab2:ab" & (lastCell - 1))
set personalization1List to the value of the range ("v2:v" & (lastCell - 1))
--.... blah blah blah...
close workbook 1 without saving
end tell
set vendorItem to ""
set personalization1 to ""
set nr to ""
set vendorItem to item i of vendorItemList as string
if vendorItem = "xxxx" then
--do lots of applescript things which I won't bore you with.
end
--the script gets to a handle call:
addLineItems(shipmentNumber, i)
---more stuff
end on
on addLineItems(shipmentID, x)
tell application "FileMaker Pro Advanced"
tell document "someDoc.fp7"
tell table "thisTable"
set nr to create new record at end
tell nr
set cell "FK_STshipment" to shipmentID
set vendorItem to item x of vendorItemList as string
--The script fails on the above line saying that the vendorItemList is not defined.
--more stuff
end
end
end
end
end
end on addLineItems