Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iRock1

macrumors 65816
Original poster
Apr 23, 2011
1,081
144
So basically the idea is to have a keyboard shortcut to open the latest downloaded file (in the Downloads folder). What's the simplest way of doing that? :confused:

Thanks in advance!
 
Last edited:

ideal.dreams

macrumors 68020
Jul 19, 2010
2,378
1,079
Automator can accomplish this. Just set up the steps in a service, save it, and then assign a key combination to it in the keyboard settings of System Preferences.
 

~Shard~

macrumors P6
Jun 4, 2003
18,377
48
1123.6536.5321
Automator can accomplish this. Just set up the steps in a service, save it, and then assign a key combination to it in the keyboard settings of System Preferences.

Exactly, just play around with Automator to accomplish this - it's not used by many users frequently but is quite powerful in the right circumstances and can make the automation of tasks such as this much easier.
 

iRock1

macrumors 65816
Original poster
Apr 23, 2011
1,081
144
I guess you could do it with Applescript.

Something like getting the latest downloaded file, opening with the default application and finally assigning a shortcut.

Sorry but how could I work this out? I don't know anything about programming so I don't know how to put these two texts together.

Code:
tell application "Finder"
    set latestFile to item 1 of (sort (get files of (path to downloads folder)) by creation date) as alias
    set fileName to latestFile's name
end tell

Code:
do shell script "open " & dstfile

In other words, how should the entire text in AppleScript look?

Automator can accomplish this. Just set up the steps in a service, save it, and then assign a key combination to it in the keyboard settings of System Preferences.

Exactly, just play around with Automator to accomplish this - it's not used by many users frequently but is quite powerful in the right circumstances and can make the automation of tasks such as this much easier.

I know it's a great tool, but honestly sometimes it looks quite difficult to use. For instance in this particular case, which actions would you chose and in which order? :S
 

ideal.dreams

macrumors 68020
Jul 19, 2010
2,378
1,079
I know it's a great tool, but honestly sometimes it looks quite difficult to use. For instance in this particular case, which actions would you chose and in which order? :S

It's actually very easy to use but after looking in to it, it looks like Automator won't be able to do this for you. You would use the "Find Finder Items" and "Open Finder Items" actions in that order, but unfortunately the "Find Finder Items" can't find items that are the newest in a folder. It can search by date created, but only with a date. There appears to be no way to tell it to open the most recent file, unless I missed something.

So it does look like you'd be better off using AppleScript but unfortunately I'm not familiar with it so I won't be able to help you any further. Good luck.
 

chickenwingfly

macrumors 6502a
Mar 8, 2012
633
22
Sorry but how could I work this out? I don't know anything about programming so I don't know how to put these two texts together.
I never used AppleScript before, but then I realized it's pretty simplistic, basically, you'd put this into an AppleScript (use built-in OS X Editor an "Run" to test)
Code:
tell application "Finder"
	set latestFile to item 1 of (sort (get files of (path to downloads folder)) by creation date) as alias
	set fileNameP to POSIX path of latestFile
end tell

do shell script "open " & fileNameP & ""

And then read the third link I shared and follow instructions to assign a keyboard shortcut.
 

iRock1

macrumors 65816
Original poster
Apr 23, 2011
1,081
144
I never used AppleScript before, but then I realized it's pretty simplistic, basically, you'd put this into an AppleScript (use built-in OS X Editor an "Run" to test)
Code:
tell application "Finder"
	set latestFile to item 1 of (sort (get files of (path to downloads folder)) by creation date) as alias
	set fileNameP to POSIX path of latestFile
end tell

do shell script "open " & fileNameP & ""

And then read the third link I shared and follow instructions to assign a keyboard shortcut.

Thanks, it works great most of the times. The problem is that the script should consider the date when the file was "added", not "created". Otherwise it works randomly.

Sadly I don't know how to give that instruction to AppleScript (I tried replacing "creation date" by "addition date", lol), and neither it's on the AppleScript Dictionary.

The only thing that I found was this: http://macscripter.net/viewtopic.php?id=37910. So I learn that there is no simple way of making this particular property accessible from AppleScript. Then I got lost in the middle of the thread. :(

BTW I've never understood the difference between sorting files by date added and date created…
 
Last edited:

chickenwingfly

macrumors 6502a
Mar 8, 2012
633
22
BTW I've never understood the difference between sorting files by date added and date created…

I don't remember quite correctly but that was one of the reasons I ditched Finder completely and found Path Finder.
Basically, one is the date the file was created on the remote server (i.e where you downloaded the file from), and seems to be the one Finder enjoys sorting by.
So I had a lot of downloaded files and no way to tell when I exactly downloaded them as they showed dates years ago (when they were created).

You can see solutions to this problem here and here, or even here.
So, instead of playing around with the piece of script I pasted you could just "fix" the problem from the root.

If you wanna play with Applescript like you did, then something like this may help, but it's not for the faint of heart (but in your case, shall you do what's mentioned in the last paragraph, this right here would mean the solution for all files in your download folder, not just the ones you add from now on; now meaning whenever you implement what is instructed in the last paragraph).

PD:
In a broad sense, I'd explain what you ask like this:
I create a file and upload to a server (apple.com/iTunesInstaller.dmg). Creation date is 13-Dec-2012.
Then you download it today. Modification date is probably 03-Jun-2013, since the download process involved adding some attributes (read, write for the current user), hence the file was modified.
Added date is I think, where it got added to the filesystem so it should be the same as Modification date.
When you modify the file tomorrow, then Creation and Added date will stay the same, but Modification date will change.
There is also Last accessed date, which is where you last opened the file (?).

Anyway, its confusing and I don't give it too much thought, all I know is that I sort my files by Modification date always.

Please notice that some servers may or may not return the original attributes of the file (it also depends on how you copied the file to the remote server) so Creation date not always means the real creation date of a given file.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.