Archive. This is an archive of the Apple Support Community. Discussions are being restored and soon you will be able to read and post here again.

How to make home folder path universal in AppleScript?

Universal name for home folder in Applescript


In an effort to use various scripts on multiple macs, I am trying to find a way in this script that would replace users/**** with whatever would make it universal to all macs or how the script must be changed.


I assume it would work on Golden Gate as well ….though assumptions are dangerous 😀


tell application "Finder"

open POSIX file "/Users/****/Desktop/ICONS"

end tell


Thanks

4 replies

Other variations:


use scripting additions

property USER : short user name of (system info)

tell application "Finder" to open ((path to desktop) & "SVG:") as text
set afolder to "/Users/" & USER & "/Desktop/PDF"
tell application "Finder" to open folder (POSIX file afolder as alias)
tell application "Finder" to open folder ((path to home folder as text) & "Library:") as alias




Use:


tell application "Finder"

open file "ICONS"

end tell


If you need a full path for items not on the desktop, use 'home' to refer to it.

If you need an UNIX-style path, use ~ instead of /Users/username.


(265395)

Hi,

This doesn't seem to work:


tell application "Finder"

open file "ICONS"

end tell


Don't I need to substitute either the Users/**** with something to make it generic to all macs or rework the script?

Replacing Users/**** with ~ or home doesn't work either


tell application "Finder"

open POSIX file "/Users/****/Desktop/ICONS"

end tell

Think I got it:


tell application "System Events"

set targetFolder to folder "~/DESKTOP/ICONS"

tell application "Finder" to open targetFolder

end tell