My scripts cannot find handler scripts located in the Script Libraries folder. Given the following handler placed in the ~/Library/Script Libraries folder titled My Library:
on formatDate(dateToConvert)
set {year:y, month:m, day:d} to dateToConvert
tell (y * 10000 + m * 100 + d) as string to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7 thru 8
end formatDate
Every attempt to call this handler fails with the 1708 error “«script» doesn’t understand the “formatDate” message.” "
Here are some of my scripts calling this handler:
use AppleScript version "2.8"
use scripting additions
set todaysDate to current date
use myLib : script "My Library"
myLib's formatDate(todaysDate)
use AppleScript version "2.8"
use scripting additions --With or without this line
set todaysDate to current date
tell script "My Library"
formatDate(todaysDate)
end tell
use AppleScript version "2.8"
use scripting additions --With or without this line
set todaysDate to current date
script "My Library"'s formatDate(todaysDate)
…and many more. I am a bit new to Applescript and I have read dozens of on line pages and two books. I cannot figure out what I am doing wrong with this code. Some hwelp would be appreciated. Paying ahead: Thanx!
I understand Ed. However, I have re-compiled many times, forced quit on the script editor many times, moved the library file to the system library script libraries folder, even upgraded MacOS to version 13 Ventura. This situation has been plaguing me for weeks. Nothing I do seems to help.
use AppleScript version "2.8"
use scripting additions
use myLib : script "My Library"
set todaysDate to current date
myLib's formatDate(todaysDate)
I appreciate the help. So I am thinking perhaps if I provide the full reply, perhaps it might help. Anyway here is what I get when I run this above script:
tell current application
current date
--> date "Wednesday, November 2, 2022 at 9:36:22 PM"
end tell
tell application "Script Editor"
formatDate(date "Wednesday, November 2, 2022 at 9:36:22 PM")
--> error number -1708
Result:
error "script \"My Library\" of «script» doesn’t understand the “formatDate” message." number -1708 from script "My Library"
Of course… It is posted in my first text of this conversation. Here it is again:
on formatDate(dateToConvert)
set {year:y, month:m, day:d} to dateToConvert
tell (y * 10000 + m * 100 + d) as string to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7 thru 8
end formatDate
on formatDate(dateToConvert)
set {year:y, month:m, day:d} to dateToConvert
tell (y * 10000 + m * 100 + d) as string to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7 thru 8
end formatDate
Next I run this…
use scripting additions
use theLib : script "My Library"
set todaysDate to current date
theLib's formatDate(todaysDate)
The result was: “2022-11-04”
Something that happen to me more and twice is the AppleEvents could hang or something simulare. The solution is: to reboot the computer
use scripting additions
on formatDate(dateToConvert)
set {year:y, month:m, day:d} to dateToConvert
tell (y * 10000 + m * 100 + d) as string to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7 thru 8
end formatDate
And called it with this script:
use scripting additions
use myLib : script "My Library"
set todaysDate to current date
myLib's formatDate(todaysDate)
Shane… Concerning my library and your question. Initially I had an additional script in the same file (My Library). I removed it in my attempts to get it working. Right now this script is the only script in the My Library file.
Concerning other files that are in the ~Library/Script Libraries, yes there are some other files. In fact, I placed the calling script in that directory trying to get it to work. Most of these files have been added during my effort to get this working. This directory was empty when I started, in fact I just recently, last month, created the directory following instructions concerning library creation. However, in view of your comment, I moved all of the files to my user directory except for the one My Library script. After that, running the calling script produced the same result.
I must admit, I was saving the scripts as .scpt files. I had no idea that they needed to be saved as .scptd. In fact, I was under the impression that the handler scripts saved as bundles had to have dictionaries with them. That is why I never tried .scptd.
I have read and re-read many sites searching for this solution. Is there some place the directs that handlers “have to” be saved as bundles? If so, I missed it and I would like to go back and read that particular site.
Libraries with dictionaries must be saved as bundles. I have found that it seems to work better on ordinary libraries, but no, I haven’t found that documented anywhere. In fact I have found sample libaries using the .scpt format.
I only use .scptd format for libraries. (I’m guessing Shane does too?)