I’ve used the following code in an app for many years and I’ve just got around to updating it. Whilst this worked perfectly before it now causes the app to crash. In my searches it seems that this has been deprecated but I can’t find an example of how it needs to be updated.
on getCAS:sender -- triggered by button in main window
tell current application's NSApp to beginSheet:WindowCAS modalForWindow:mainWindow modalDelegate:me didEndSelector:"CASSheetDidEnd:returnCode:contextInfo:" contextInfo:(missing value)
end getCAS:
-- connected to button in customWindow
on CASSheetButtonPushed:sender -- triggered by button in sheet
set thetitle to the sender's title as text
--to avoid empty boxes
if thetitle = "Get Structure" then
set returnCode to 0 -- use different numbers for different buttons
--empty box
if (CasNumber as text) = "missing value" then
set returnCode to 2
end if
set CasNumber to replace_chars((CasNumber as text), " ", "") as text
--log returnCode
--log CasNumber
tell current application's NSApp to endSheet:WindowCAS returnCode:returnCode
else if thetitle = "Get List" then
set returnCode to 1
--empty box
if (casList as text) = "missing value" then
set returnCode to 2
end if
tell current application's NSApp to endSheet:WindowCAS returnCode:returnCode
else if thetitle = "Cancel" then
set returnCode to 2
tell current application's NSApp to endSheet:WindowCAS returnCode:returnCode
end if
-- the following call closes the window and results in CASSheetDidEnd_returnCode_contextInfo_ being called
--tell current application's NSApp to endSheet_returnCode_(WindowCAS, returnCode)
end CASSheetButtonPushed:
-- called when window is closed
on CASSheetDidEnd_returnCode_contextInfo_(theSheet, returnCode)
log returnCode
log CasNumber
--set returnCode to returnCode as integer
if returnCode = 0 then
--set theSaveFile
set the_SMILES to get_smiles(CasNumber) as text
set the_path to path to desktop as string
set posix_the_path to POSIX path of the_path
set output_file_path to posix_the_path & "output.smi" as text
set theSaveFile to output_file_path as text
--log theSaveFile