You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Getting path to user's home directory

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.

MacBook, Mac OS X (10.4.11)

Posted on Aug 6, 2008 4:29 PM

Reply
Question marked as Top-ranking reply

Posted on Aug 6, 2008 5:34 PM

AppleScript's Standard Additions has a path to command with several constants defined, such as:

get path to home folder
8 replies

Aug 6, 2008 6:31 PM in response to Barry Margolin

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

Aug 6, 2008 7:43 PM in response to Tom_X

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?

Getting path to user's home directory

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.