Imported from the Apple Support Forums via the Wayback Machine 🔗
I have some Applescripts that I've written at work and I'd like to share with coworkers. The problem is that I've currently got my home directory path hard-coded in some of them, e.g.
set theScript to load script file ":Users:bmargoli:Library:Scripts:Lib:RunInTerminal.scpt"
I'd like to rewrite this to be more portable, so everyone doesn't have to personalilze their copies of the scripts. How would I rewrite the above line to get the user's home directory, and then find the Library/Scripts/Lib folder within it.
Imported from the Apple Support Forums via the Wayback Machine 🔗
AppleScript's Standard Additions has a path to command with several constants defined, such as:
get path to home folder
0
Tom_X·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Here's two examples...
open the Lib folder...
try
do shell script "open ~/Library/Scripts/Lib\ folder"
end try move the Lib folder to the desktop...
tell
application "Finder"
set
home_path to
home as
Unicode text
try
set
source to
alias (
home_path & "Library:Scripts:Lib folder") as
Unicode text
set
destination to
home_path & "Desktop" as
Unicode text
tell
application "Finder" to
move
source
to
destination as
Unicode text
end try
end tell
0
Tom_X·
Imported from the Apple Support Forums via the Wayback Machine 🔗
this is what you want but you will have to save the script as an .app
try
do shell script "open -a ~/Library/Scripts/Lib/RunInTerminal.app"
end try
0
Barry Margolin·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Making RunInTerminal a .app won't work, since all it contains are subroutines that other scripts can use.
When I first created the library I tried using "get path to home folder", but I was unable to combine that with "Library/Scripts/Lib" to get it to load the script library. I don't remember the errors I got. Can someone show the whole sequence?
0
red_menace·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Give this a try:
set theScript to load script file (get path to scripts folder from user domain as text) & "Lib:RunInTerminal.scpt"
0
Niel·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Try using:
alias ((path to home folder as string) & "Library:Scripts:Lib")
(34492)
0
Barry Margolin·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Red_menace, your solution worked when I wrapped an extra set of parentheses around it.
Thanks.
0
Camelot·
Imported from the Apple Support Forums via the Wayback Machine 🔗
move the Lib folder to the desktop...
Then it no longer becomes your Lib folder, just another folder sitting on the Desktop.