Path to folder on desktop...


I’m working on converting an OS9 script to OSX. The script refers to a folder on the users’ desktop, whose path is obviously different for each OS (the folder is called “Coding Logs”). The script needs to work on different Macs for different people, so I can’t specify the Mac or User name. I have two problems:

  1. In OSX, how can I refer to a folder on the User’s desktop, without specifying the User or Mac name? In OS9 it’s easy, because there’re no users, so I can just do this:
 set codingLogFolder to alias ((name of startup disk) & ":Desktop Folder:Coding Logs:")

The only code I know that works in OSX is this, but it specifies the user (in this case, “guest”):

set codingLogFolder to alias "Work:Users:guest:Desktop:Coding Logs:"

(Note, that “Work” is the name of the partition where the User directories reside. It is the same setup for each Mac that this script will run on.)

  1. Ideally, the script heeds to temporarily run on both OS’s. Since the syntax for specifying the folder location is different, is this possible? Can I get the script to check which OS it’s on first?

Everything else about the script works the same in both environments, so this is this only thing I’m stuck on.


Take a look at ‘path to’ in Standard Additions. This might provide an idea of how you can use it.

set ptd to path to desktop as Unicode text
set path_ to (ptd & "Coding Logs:")

– Rob

You can use (path to “desk”) to refer to the desktop. Also, see Rob Jorgensen’s Show Path Codes script for a list of other special folder codes.

One caveat to this is that if the call to the “path to” command is inside a Finder tell block, you need to change it from “path to desktop” to “path to desktop folder”:


[This script was automatically tagged for color coded syntax by Script to Markup Code]

Furthermore, if you are working with the Finder, you can eliminate paths altogether and use something like this.

tell application "Finder"
	open folder "Coding Logs" of desktop
end tell

– Rob

Also, I beleive the Finder refers to the desktop directly, as in

tell application "Finder"
	open folder "Stuff"
end tell

Assuming a folder named “Stuff” is on your desktop.

Hey guys, thanks! The solution was simple as usual, and works in both OS’s.

set codingLogFolder to folder "Coding Logs" as string