Getting filepath on any computer

Hey,

I am brand new at applescript and trying to figure out a filepath issue i’m having!

What would be the best way to get the file path to a folder on any computer that runs my script? I have a script that takes a picture using photobooth, and I want to then manipulate that image, but to do that I need to be able to find the photo in the:

“Macintosh HD:Users:NAME:Pictures:Photo Booth” folder… The issue is that the name of the user is different on every computer!

How can I hardcode this filepath so that it is accurate for every computer that runs my script?

Thanks,

Derek

Hello.
This should do the trick:


set ppath to (path to pictures folder as text) & "Photo Booth"

The path to command can return paths to many standard folders on your computer. It would normally return an alias, so you can give it the parameter (not a coercion), in order to be able to use it as a part of a path containing extra text.

Best Regards

McUsr

Great! This is exactly what I needed!

Here’s my final code, and it works perfectly- thanks!

set theItems to {}
set ppath to (path to pictures folder as text) & "Photo Booth"

tell application "Finder"
	set theItems to (every file of folder ppath whose name extension is "jpg") -- get matching files
	set theItems to (sort theItems by modification date) -- sort by property
	set picFile to first item of theItems as text
end tell

tell application "Preview" to open file picFile