Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > OS X > OS X 10.8 Mountain Lion

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 1, 2013, 07:32 PM   #1
iRock1
macrumors 6502
 
Join Date: Apr 2011
How could I create a script or "something" like this…?

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?

Thanks in advance!

Last edited by iRock1; Jun 2, 2013 at 08:10 PM.
iRock1 is offline   0 Reply With Quote
Old Jun 1, 2013, 09:06 PM   #2
ipsychedelic
macrumors 6502a
 
ipsychedelic's Avatar
 
Join Date: Mar 2012
Location: Cali, Colombia
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.
ipsychedelic is offline   0 Reply With Quote
Old Jun 2, 2013, 12:26 AM   #3
ideal.dreams
macrumors 68000
 
ideal.dreams's Avatar
 
Join Date: Jul 2010
Location: OH
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.
__________________
15" rMBP: 256GB SSD, 8GB RAM, 2.3 GHz Quad Core i7, OS X 10.9.2
White iPhone 5s: 32GB, iOS 7.1
White iPad Air 16GB + WiFi, iOS 7.1
ideal.dreams is offline   0 Reply With Quote
Old Jun 2, 2013, 01:01 AM   #4
~Shard~
macrumors P6
 
~Shard~'s Avatar
 
Join Date: Jun 2003
Location: 1123.6536.5321
Send a message via Skype™ to ~Shard~
Quote:
Originally Posted by ideal.dreams View Post
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.
__________________
My riches consist not in the extent of my possessions, but in the fewness of my wants.
- J. Brotherton
~Shard~ is offline   0 Reply With Quote
Old Jun 2, 2013, 08:09 PM   #5
iRock1
Thread Starter
macrumors 6502
 
Join Date: Apr 2011
Quote:
Originally Posted by ipsychedelic View Post
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?

Quote:
Originally Posted by ideal.dreams View Post
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.
Quote:
Originally Posted by ~Shard~ View Post
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
iRock1 is offline   0 Reply With Quote
Old Jun 2, 2013, 10:16 PM   #6
ideal.dreams
macrumors 68000
 
ideal.dreams's Avatar
 
Join Date: Jul 2010
Location: OH
Quote:
Originally Posted by iRock1 View Post
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.
__________________
15" rMBP: 256GB SSD, 8GB RAM, 2.3 GHz Quad Core i7, OS X 10.9.2
White iPhone 5s: 32GB, iOS 7.1
White iPad Air 16GB + WiFi, iOS 7.1
ideal.dreams is offline   0 Reply With Quote
Old Jun 2, 2013, 10:43 PM   #7
ipsychedelic
macrumors 6502a
 
ipsychedelic's Avatar
 
Join Date: Mar 2012
Location: Cali, Colombia
Quote:
Originally Posted by iRock1 View Post
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.
ipsychedelic is offline   0 Reply With Quote
Old Jun 3, 2013, 06:58 PM   #8
iRock1
Thread Starter
macrumors 6502
 
Join Date: Apr 2011
Quote:
Originally Posted by ipsychedelic View Post
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 by iRock1; Jun 3, 2013 at 07:37 PM.
iRock1 is offline   0 Reply With Quote
Old Jun 3, 2013, 10:09 PM   #9
ipsychedelic
macrumors 6502a
 
ipsychedelic's Avatar
 
Join Date: Mar 2012
Location: Cali, Colombia
Quote:
Originally Posted by iRock1 View Post
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 by ipsychedelic; Jun 3, 2013 at 10:19 PM.
ipsychedelic is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > OS X > OS X 10.8 Mountain Lion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
"Date modified" script strange behavior in Mavericks Remcokw Mac Programming 7 Mar 12, 2014 04:40 PM
Script to prevent Macbook with "Replace Soon" battery from crashing spt MacBook Pro 0 Jun 13, 2013 02:03 PM
"Potentially useful" Abbyy Fine Reader script. (does not replace input file) tiriya Mac Programming 0 Aug 9, 2012 08:19 AM
iTunes Apple script for additional "View Options"? kumquat Apple TV and Home Theater 14 Jun 29, 2012 09:02 AM
iCal "Run Script" alert opens .scpt file in AppleScript Editor instead of running it drskot Mac Programming 3 Jun 7, 2012 12:47 PM

Forum Jump

All times are GMT -5. The time now is 02:13 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC