Applescript is 27 times slower when run from Menu Bar compared to running it from Script Editor
Running an Applescript that gets the name for selected person in Contacts app and puts it into cells in a Numbers table. When run from the Script Editor it takes about a second. The same script when run via the Menu Bar takes 27 seconds. This is on an M2 Mac Mini running Sonoma 14.4.1. On this Mac, I also have a script that gets information from the Contacts app and generates an Invoice worksheet in Numbers. It runs as fast from the Menu Bar as it does from the Script Editor. I have no idea why this is happening to this one script or how to make it run normally. I would appreciate assistance with this issue.
I have also run the same script from the Menu Bar on another Mac - an M1 Mac Studio running Sonoma 14.4.1 - and it runs in about a second.
Here is the script:
(* The purpose of this script is to put the last name and first name of a customer into a numbers monthly finishing order listing by copying the information out of the Contacts App.
The script assumes that the Contacts app is open to the customer that is to be placed into the numbers document and that the cursor in the numbers document is in the row in which the name info is to be placed.
*)
-- Get the first and last name of customer or company and first name of contact from Contacts
tell application "Contacts"
activate
set the theID_Customer to the first person whose selected is true
set textLastName to last name of theID_Customer
set textFirstName to first name of theID_Customer
set textOrg to organization of theID_Customer
set boolIsCompany to company of the theID_Customer
end tell
-- Get the month name of the current date to compare with the Finishing Workbook sheet name chosen
set textMonthName to month of (get current date) as text
-- Make sure the finishing workbook is open and cursor is set in the sheet for the current month in a row that has name fields blank. Fill in name
tell application "Numbers"
activate
try
if not (exists document 1) then error number 1000
tell document 1
tell active sheet
set textNameOfSheet to name
if textMonthName ≠ textNameOfSheet then error number 1001
-- next statement can cause the execution error if no Table is selected
set the ID_selectedTable to (the first table whose class of selection range is range)
tell ID_selectedTable
set textNameOfTable to name
if textNameOfTable ≠ "MFOL=NpF_MonthlyFinishingOrderListing" then error number 1002
set theRow to (address of row of selection range) as string
set cellLastName to "F" & theRow
set cellFirstName to "G" & theRow
set cellSHOP to "H" & theRow
set cellDescrip to "J" & theRow
set makeRange to "I" & theRow & ":I" & theRow
if value of cell (cellLastName) ≠ missing value or value of cell (cellFirstName) ≠ missing value or value of cell (cellDescrip) ≠ missing value then error number 1003
tell cell (cellLastName)
if boolIsCompany is false then
set value to textLastName
else
set value to textOrg
end if
end tell
tell cell (cellFirstName)
set value to textFirstName
end tell
tell cell (cellSHOP)
set value to boolIsCompany
end tell
set selection range to range makeRange
end tell
end tell
end tell
-- if an error has occurred, this is what will be said
on error errorMessage number errorNumber
if errorNumber is 1000 then
set stringAlert to "FINISHING WORKBOOK NOT OPEN"
set errorMessage to "Please open this years Finishing Workbook and select the sheet for the current month and the next available blank row in the MFOL Table. Then rerun this script."
else if errorNumber is 1001 then
set stringAlert to "SELECT CURRENT MONTH WORKSHEET"
set errorMessage to "You have " & textNameOfSheet & " Sheet selected. Please select " & textMonthName & " Sheet and the first blank row in the MFOL Table, Then rerun this script."
else if errorNumber is 1002 then
set stringAlert to "SELECT MFOL TABLE"
set errorMessage to "Please select the MFOL Table and the first blank row in the table. Then rerun this script."
else if errorNumber is 1003 then
set stringAlert to "NOT A BLANK ROW"
set errorMessage to "Please select the first blank row in the MFOL table. Then rerun this script."
else
set stringAlert to "NO TABLE IS SELECTED"
set errorMessage to "Please select the MFOL Table and the first blank row in the table. Then rerun this script"
end if
display alert stringAlert message errorMessage buttons {"Cancel"}
error number -128 -- quit execution of script
end try
end tell
Mac mini (M2, 2023)