According to the AppleScript Language Guide – section 3 of quoted portion below. I should be able to put library scripts in a folder specified by the OSA_LIBRARY_PATH folder.
I have set my OSA_LIBRARY_PATH to ~\APPLESCRIPT\SCANGLOBAL2\Script Libraries using the command
Export OSA_LIBRARY_PATH=/Users/bcrow/APPLESCRIPT/SCANGLOBAL2/Script\ Libraries.
I checked that the environment variable had been changed by executing
printenv
which shows
OSA_LIBRARY_PATH=/Users/bcrow/APPLESCRIPT/SCANGLOGAL2/Script Libraries
After first testing that the attached script email_functions_lib3 standalone.scpt works if the library scripts are in ~\Library\Library Scripts, I copied the library scripts to the OSA_LIBRARY_PATH folder and renamed the originals.
When I run the program, the compiler throws an AppleScript Execution Error “Cant get script ‘UI_functions_lib’”
Is there some reason the Script Debugger compiler is not searching for script in the OSA_LIBRARY_PATH?
I want to keep libraries in a folder with my main AppleScript program because I am using Mercurial to control revisions, which will not work if the library files are off in some unassociated folder.
Excerpt from AppleScript Language Guide at
https://developer.apple.com/library/mac/documentation/AppleScript/Conceptual/AppleScriptLangGuide/conceptual/ASLR_script_objects.html#//apple_ref/doc/uid/TP40000983-CH207-SW6
Paragraph 3 Bolding added by me.Mac Developer LibraryDeveloper
Creating a Library
The basic requirement for a script to be a script library is its location: it must be a script document in a “Script Libraries” folder in one of the following folders. When searching for a library, the locations are searched in the order listed, and the first matching script is used:
- If the script that references the library is a bundle, the script’s bundle Resources directory. This means that scripts may be packaged and distributed with the libraries they use.
- If the application running the script is a bundle, the application’s bundle Resources directory. This means that script applications (“applets” and “droplets”) may be packaged and distributed with the libraries they use. It also enables applications that run scripts to provide libraries for use by those scripts.
- Any folders specified in the environment variable OSA_LIBRARY_PATH. This allows using a library without installing it in one of the usual locations. The value of this variable is a colon-separated list of paths, such as /opt/local/Script Libraries:/usr/local/Script Libraries. Unlike the other library locations, paths specified in OSA_LIBRARY_PATH are used exactly as-is, without appending “Script Libraries”. Supported in OS X v10.11 and later.
- The Library folder in the user’s home directory, ~/Library. This is the location to install libraries for use by a single user, and is the recommended location during library development.
- The computer Library folder, /Library. Libraries located here are available to all users of the computer.
- The network Library folder, /Network/Library. Libraries located here are available to multiple computers on a network.
- The system Library folder, /System/Library. These are libraries provided by OS X.
- Any installed application bundle, in the application’s bundle Library directory. This allows distributing libraries that are associated with an application, or creating applications that exist solely to distribute libraries. Supported in OS X v10.11 and later.
This is the text of the calling Applescript
use AppleScript version “2.4” – Yosemite (10.10) or later
use scripting additions
–BEGIN add for standalone
set FinalFilePathName_Passed to "EulerHD:Users:bcrow:Downloads:test PDF copy 2.pdf"
set POMessage to true
use libUIfunctionslib : script "UI_functions_lib"
use libserverfunctionslib : script “server_functions_lib”
property dialogchoiceList : libUIfunctionslib’s dialogchoiceList
property TestServerConnection : libserverfunctionslib’s TestServerConnection
set ServerNameStr1 to “xxxxx”
set UserNameStr1 to "xx”
set UserPswdStr1 to “xxxxx”
set ServerNameStr2 to “xxxx”
set UserNameStr2 to “xxx”
set UserPswdStr2 to “xxx”
TestServerConnection(ServerNameStr1, UserNameStr1, UserPswdStr1)
TestServerConnection(ServerNameStr2, UserNameStr2, UserPswdStr2)
–END add for standalone
set Email_RecipientsList to {}
set Email_AddressesList to {}
set EmailFullPathFileName to “Not Yet Defined"
set shortName to {”"}
set ChoiceList to {""}
set AddresseeCount to 0
set choiceK to “Not Yet Defined”
set EmailFullPathFileName to “ELC:Shared:IT:Scan Name Utility:Employee List.txt”
–set EmailFullPathFileName to “ELC:Shared:IT:Scan Name Utility:SNAFU email list.csv”
–open email file and create list of lines
–set fileHandle to (“EulerHD:Users:bcrow:Desktop:SNAFU email list.csv”)
–set fileHandle to open for access file "/Volumes/ELC/Shared/IT/Scan Name Utility/SNAFU email list.csv"
set fileHandle to (open for access file EmailFullPathFileName)
set theLines to paragraphs of (read fileHandle)
close access fileHandle
–close file after theLines is created
set addresseeListCount to count of theLines
set original_delimiters to text item delimiters
set text item delimiters to “,”
–>>emailGroup
set ChooseTitle to "Send Email"
set ChoosePrompt to “Click on Email recipient(s)
Add address with COMMAND-click”
–create choiceList which will include “Do Not Send”, “Other eMail Address”, two group names and full names of all addressees
set (first item of ChoiceList) to “Do Not Send” as string
copy “Other Email Address” to end of ChoiceList
copy “Sample to TBP Group” to end of ChoiceList
copy “Equipment to TBP Group” to end of ChoiceList
–repeat with J from 5 to (addresseeListCount + 3)
repeat with J from 5 to (addresseeListCount - 3)
–set k to J - 4
set k to J + 1
set choiceK to text item 3 of (item k of theLines) as string
copy choiceK to end of ChoiceList
end repeat
set EmaileesChosenList to dialogchoiceList(ChooseTitle, ChoosePrompt, ChoiceList)
–Item 1 of EmaileesChosenList is a LIST of addressee long names