Unix-type pathnames in AppleScript?

Is there such thing as Unix-style pathnames in AppleScript?
For example, something like the following (both of which which give me an error):

tell application “Finder” to select item “~/Desktop/filename”

tell application “Finder” to select item alias “~/Desktop/filename”

I’ve been having to use something like the following syntax:

tell application “Finder” to select item “filename” of folder “Desktop” of folder “username” of folder “Users” of disk “diskName”

… which doesn’t exactly give one a truly portable script.

Is there any way to work-in Unix-style pathnames into AppleScripts?

Thanks!

For the example you’ve given, you’d use AppleScript’s way of doing it:

read (path to desktop as text) & "myFile"

AppleScript “knows” where these are (not all of which are useful in OS X systems):

path to application support/applications folder/desktop/desktop pictures folder/documents folder/favorites folder/Folder Action scripts/fonts/help/home folder/internet plugins/keychain folder/library folder/modem scripts/movies folder/music folder/pictures folder/preferences/printer descriptions/public folder/scripting additions/scripts folder/shared documents/shared libraries/sites folder/startup disk/startup items/system folder/system preferences/temporary items/trash/users folder/utilities folder/workflows folder/voices/apple menu/control panels/control strip modules/extensions/launcher items folder/printer drivers/printmonitor/shutdown folder/speakable items/stationery : the folder to return
[from system domain/local domain/network domain/user domain/Classic domain] : where to look for the indicated folder
[as type class] : the type to return: alias or string (default is alias)
[folder creation boolean] : Create the folder if it doesn’t exist? (default is true)
→ alias : the path to the specified folder

If the item is on the desktop, Schmye, Finder needs no further information. Just use something like:

tell application "Finder" to select file "filename"

For other locations, there’s the ‘path to’ command from Standard Additions’ File Commands. For example:

tell application "Finder" to select file ((path to applications folder as Unicode text) & "Mail.app")

For true portability, coerce to Unicode text (as shown here), rather than to text. This should preserve the more ‘exotic’ Unicode characters that might exist on some machines.

To see the range of options (as Adam quoted) at any time, check out Standard Additions’ AppleScript dictionary.

Schmye:

Some applications (iPhoto, for instance) store their pathnames as UNIX style. To convert them to Unicode so that AppleScript can access them, use this:

set a to "/Users/casdvm/Pictures/jumping.jpg"
set b to POSIX file a

-->file "VelociDrive:Users:casdvm:Pictures:jumping.jpg"

If you need to go back the other direction (or just want to because it’s cool), use this:

set b to "VelociDrive:Users:casdvm:Pictures:jumping.jpg"
set c to POSIX path of b

-->"/Users/casdvm/Pictures/jumping.jpg"

“POSIX file” is the way to go (if you prefer POSIX-path notation), as the others have shown.

Only a note: trying the “as Unicode text” coercion over some aliases will fail with “hi-unicode” characters (I didn’t try with “path to”, as I don’t have a machine with such hi-unicode, but it should be the same for this command’s result -an alias).

I think this is a bug (or lack of a real strong Unicode support in AS). In this case, you must use POSIX paths to work with the “texts”, then use “POSIX file” at the end to create a solid alias spec (I’ll post some examples if needed). For example, “path to desktop as Unicode text” should error if the path contains hi-unicode.