Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create an AppleScript snippet that locates the current random wallpaper and reveals it in Finder. I have the following snippet which finds the current wallpaper's POSIX path as a string:

set plistFolderPath to path to preferences folder from user domain as string
set plistPath to plistFolderPath & ""
tell application "System Events"
    tell property list file plistPath
        tell contents
            set thePath to value of property list item "NewChangePath" of property list item "default" of property list item "Background" & "/" & value of property list item "LastName" of property list item "default" of property list item "Background"
        end tell
    end tell
end tell

thePath is now a string in the form:

/Volumes/Archive/Widescreen wallpaper/12345_Name_2560x1440.jpg

(Note spaces)

I try to reveal this path in FInder, but everything I've tried results in an error:

tell application "Finder"
    reveal POSIX file of quoted form of thePath (* Error: "Can't get POSIX file of (blah)" *)
end tell

How do I reveal a pathname in Finder in AppleScript when all I have is its POSIX path?

share|improve this question
up vote 8 down vote accepted

I think your problem is that quoted form. Try something like this:

set thePath to POSIX file "/Volumes/Lion HD/Users/ngreenst/Desktop/image.jpg"
tell application "Finder" to reveal thePath

So, just reveal thePath

share|improve this answer
This works if I paste a path directly into the script as you did, but if I use reveal POSIX file thePath it returns a "Can't get POSIX file <path>" error. – Brant Bobby Oct 2 '11 at 16:56
@BrantBobby That means that there's some problem with the path as you're receiving it. Try casting it as a string (set thePath to ... as string). If that doesn't work, I'll need to see exactly what the output is to help (I can't test; your script isn't working OMM) – Nathan Greenstein Oct 2 '11 at 17:02
Ah, adding as string did the trick! I guess my assumption that thePath was already a string was wrong. – Brant Bobby Oct 2 '11 at 17:04
set p to "/Applications/Utilities/AppleScript"

# uses an existing window or makes a new window with your default settings
tell application "Finder"
    reopen # makes a new window if there are no open windows
    set target of window 1 to (POSIX file p as text)
end tell

# makes a new window that doesn't use your default bounds or view settings
tell application "Finder"
    reveal POSIX file p as text
    activate # focuses the window
end tell
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.