Cool script! It might seem like a simple question, but how do I make this script look in another folder than my documents folder?
Easy. Just change this statement to the folder you want to use:
set thePath to POSIX path of (path to documents folder as text)
If you'd like to choose the folder at the time the macro/script is run then use this:
set thePath to POSIX path of (choose folder)
BTW, see path to (folder) for other choices for the path to
command.
Almost too easy! Thanks.
When if I want to use a custom path? One that is not a standard folder?
set thePath to "/Users/YourUserName/Documents/YourCustomFolder"
BTW, if you don't have a tool that gets the POSIX path of a folder/file, you can use this simple AppleScript, run from the Script Editor.
--- FOR FOLDERS ---
set thePath to POSIX path of (choose folder)
log thePath
--- FOR FILES ---
set thePath to POSIX path of (choose file)
log thePath
If you'd like to learn more about AppleScript, see
AppleScript: The Language of Automation
@DanThomas I tried your script in iTerm 2 as I wanted to get the name of the most recently added file. I was expected the calendar.ics file as an answer as I added it a few minutes ago. When sorting my files by "Date added" with my file manager, ForkLift, calendar.ics file is the newest one.
Here is the list I get performing ls -Urp
:
pearltrees_export.html
organising_knowledge_paper.pdf
mount.txt
je_ne_sais_pas_ce_que_je_fais.txt
if219bhfb2v51.jpg
iTerm_Selection.png
chromium-hist-bookmarks-2.1.8.zip
chromium-hist-bookmarks-2.1.8/
calendar.ics
...
pearltrees.html is a file of Oct 15th.
Do not know what to think...
Found this script on SO:
ls -Art | tail -n 1
It works as it finds calendar.ics as the newest file in my folder.
But it is named as "not very elegant".
Should I worry about that?
I don't have any idea. Sorry, that was a long time ago, and my brain isn't what it used to be.
(?)
Hey @politicus,
Dan's script finds the most recently modified file – NOT the most recently added file.
If you read through the entire thread you'll find you need to use my AppleScriptObjC script to locate the most recently added file.
-Chris