- I have a on launched theObject handler and a on open theFiles handler to handle both double clicking and drag and drop. In regular Script Editor the equivalent handlers are on run and on open theFiles.
Within Script Editor, the on run handler presents a dialog that warns the user that this app is drag and drop only. With Sript Editor, a drag and drop accesses on open theFiles and, so, no such warning happens. This is exactly what should happen.
Using AppleScript Studio, upon double clicking, the on launched theObject handler presents the same warning dialog (attached to the opening window).
However, there’s the rub; namely, drag and drop will access the same on launched theObject handler and present the same dialog warning and obviously I don’t want such a warning when doing the drag and drop.
I am presenting all the code not for this problem, but for the error -1708 problem:
property gSaved : false
on displayDialog(theMsg, theButtonsArray, theDefaultButton, theGivingUp, theIcon, theWindow)
script
property itsMsg : theMsg
property itsButtonsArray : theButtonsArray
property itsDefButton : theDefaultButton
property itsGiveUp : theGivingUp
property itsIcon : theIcon
property itsWindow : theWindow
property dd : null
property theResult : ""
on showItself()
set dd to display dialog itsMsg buttons itsButtonsArray default button itsDefButton ¬
giving up after itsGiveUp with icon itsIcon attached to window itsWindow
end showItself
on dialog ended theObject with reply dd
if (gave up of dd) then
set theResult to itsDefButton
else
set theResult to (button returned of dd)
end if
end dialog ended
end script
end displayDialog
on launched theObject -- the application
beep
set launchDlg to ¬
displayDialog("Drop one Microsoft Excel Spreadsheet on me!", {"OK"}, "OK", ¬
15, "stop", "Calculate Medical")
tell launchDlg to showItself()
tell theObject to continue quit
end launched
on allSaved()
if (not gSaved) then
beep
set continueDlg to ¬
displayDialog("You have not finished calculating your Spreadsheet." & return & ¬
"Do you wish to continue calculating?" & return & return, ¬
{"Yes", "No"}, "Yes", 15, "stop", "Calculate Medical")
tell continueDlg to showItself()
set gSaved to (theResult of continueDlg) is "No"
end if
return gSaved
end allSaved
-- clicking the "OK" button
on clicked theObject
-- display dialog name of theObject
if allSaved() then tell window of theObject to close
end clicked
-- closing the window
on should close theObject
(*
If we get here via on clicked Handler, allSaved()
doesn't present a second dialog because the
global gSaved has been set to true.
If we just close the window, then allSaved()
does present a new dialog if gSaved is false.
Ditto applies to on should quit.
*)
return allSaved()
end should close
-- CMD-Q
on should quit theObject -- the application
return allSaved()
end should quit
on should quit after last window closed theObject -- after
return true
end should quit after last window closed
on open theFiles
if ((count of theFiles) > 1) then
beep
display dialog "Drop only one Microsoft Excel Spreadsheet on me!" buttons {"OK"} ¬
default button "OK" giving up after 15 ¬
with icon "stop" attached to window "Calculate Medical"
quit
else
set theWorkbook to item 1 of theFiles
set fileCreator to file creator of (info for theWorkbook)
set fileType to file type of (info for theWorkbook)
if (fileCreator is not equal to "XCEL" or fileType does not contain "XLS") then
beep
display dialog "Drop only a Microsoft Excel Spreadsheet on me!" buttons {"OK"} ¬
default button "OK" giving up after 15 ¬
with icon "stop" attached to window "Calculate Medical"
quit
else
calculateWorksheet(theWorkbook)
saveWorksheet()
set gSaved to true
end if -- else dropped an Excel Spreadsheet as prescribed
end if -- else just one dropped file as prescribed
end open
For the life of me, I see nothing in the above code that could generate the -1708 error, which Rosenthal’s book states is “ doesn’t understand the message”
I did check under “File Owner” Inspector and I have checks for Launched, Open, Should Quit and Should Quit after last window closed.
For the button “Quit” of the main window I have checked “Action:clicked” and Key" and for the window, I have checked Should Close.