Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A one-keystroke iPod eject script Desktop
This is probably a no-brainer for many people, but it never occurred to me until today. Every morning when I wake up, I check my e-mail, take a shower [editor: get dressed?], eat breakfast, brush my teeth, and finally, grab my iPod and take off for school. Of course, I can't just "grab" my iPod and go, because it's always mounted on the dock, so I have to find my iPod icon on the desktop, right-click, and select Eject (or, left click and command-E). This process can be mildly annoying, especially when I'm in a rush.

So today, I finally decided I should try to make it as simple as a keystroke. First, I created an AppleScript (my very first, no less):
tell application "Finder"
  eject "name_of_my_iPod"
end tell
I saved it as an application (but I guess you can save it as a script) in ~/Documents -> scripts. Then, I went and downloaded Xkeys. After that, I installed Xkeys, assigned F13 to run the script application, and voila! F13 is now my own "eject iPod" key. I just wished I could assign F16 for the task, as the keyboard that came with my iMac G5 has F16.
    •    
  • Currently 2.83 / 5
  You rated: 4 / 5 (6 votes cast)
 
[18,418 views]  

A one-keystroke iPod eject script | 30 comments | Create New Account
Click here to return to the 'A one-keystroke iPod eject script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
an extention of this script
Authored by: kjell on Sep 30, '04 11:19:21AM

i wrote the same script a few weeks ago and use it everyday. the only thing i'd like to change is to have itunes update my ipod before i eject the ipod.

i figured i'd use some gui scripting to select the menu item in itunes.. but it's not working right. i posted on a livejournal community about that part of the script but nobody really helped out much.

http://www.livejournal.com/community/macosx/2999354.html

if someone can take a look i'd really appreciate it.



[ Reply to This | # ]
an extention of this script
Authored by: DougAdams on Sep 30, '04 11:41:14AM
I haven't seen your script, but this should work:
tell application "iTunes"
	try
		update "iPod"
	end try
end tell

tell application "Finder" to eject "iPod"
Obviously, substitute the name of your iPod for "iPod". The try block prevents an error if your iPod Options are set to "Manually manage..."

[ Reply to This | # ]
an extention of this script
Authored by: kjell on Sep 30, '04 12:38:29PM

thanks a lot- this works great, except that it tries to eject the ipod while it's being updated. what do i put in there to give it a 5-10 second wait or something before it ejects the ipod?



[ Reply to This | # ]
an extention of this script
Authored by: jakacmar on Sep 30, '04 02:27:30PM

I've been trying to script this forever and always run into the same problem you have. Perhaps most annoying, even if you wrap the eject command in a try statement, the Finder will still pop up the "Disk in Use" dialog box for some strange reason making it basically impossible to work around and will usually result in an endless loop. I'm not sure there is a good way to do this short of convincing Apple to make checking whether an iPod is currently being updated scriptable.



[ Reply to This | # ]
an extention of this script
Authored by: jonesy on Sep 30, '04 04:31:49PM
Try wrapping it in a handler:

on update_pod()
	tell application "iTunes"
		try
			update "iPod"
		end try
	end tell
end update_pod

update_pod

tell application "Finder" to eject "iPod"

---
Grrrr!!!!!

[ Reply to This | # ]

an extention of this script
Authored by: kjell on Sep 30, '04 04:51:40PM
that's not working for me, it disconnects the ipod without updating it. but if i insert a 10 second delay in between the two parts of the script, it works alright. ten seconds is generally long enough for me, but you guys can replace it with whatever you want.
tell application "iTunes"
	try
		update "kjell_ipod"
	end try
end tell
delay 10
tell application "Finder" to eject "kjell_ipod"


[ Reply to This | # ]
delay x
Authored by: VRic on Sep 30, '04 05:30:14PM
what do i put in there to give it a 5-10 second wait or something before it ejects the ipod?
delay x where x is the number of seconds

For example:
tell application "iTunes" to update "iPod"
delay 10
tell application "Finder" to eject "iPod"


Of course this isn't really waiting for the update to complete. Unless there's a sanctionned way to do it, one needs a workaround; maybe something like this would do:
- create a dummy playlist in iTunes (it should be the last to be sent, I don't know in what order playlists are updated)
- delete the similarly named playlist from the iPod if there's one (leftover from a previous run of the script)
- update the ipod
- wait until the playlist is on the ipod by running a "repeat until" loop testing for that list or one of it's tracks and containing nothing or a "delay 1" statement for example (I have no iPod so I don't know if you can test for a playlist on the ipod without finding the one in iTunes instead but let's say it's possible)
- delete the playlist in iTunes
- then unmount the ipod

This would make sure the update is complete without waiting unnecessarily longer (assuming one can actually be certain the dummy playlist is updated last, which may or may not be predictable).

[ Reply to This | # ]
an extention of this script
Authored by: ever on Jan 01, '05 09:46:31AM

why not just create two separate scripts for each function? hit f11 to update the ipod, and when its done just hit f12 to eject? works for me and saves hassle.



[ Reply to This | # ]
A one-keystroke iPod eject script
Authored by: DougAdams on Sep 30, '04 11:25:58AM
If iTunes is running--it always is at my house--you can click on iTunes's Dock icon and select "Eject iPod" from the pop-up. Although, the script is dandy, too ;)

[ Reply to This | # ]
A one-keystroke iPod eject script
Authored by: Fofer on Sep 30, '04 11:57:04AM

Fofer's tips for iPod automation nirvana:

#1 Uncheck the "Enable Disk Use" preference (assuming you don't need it all the time.)

#2 If you have more GBs of music than your iPod can handle, create a bunch of great playlists. Regular ones you'll listen to often and Smart ones that'll refresh. Check smartplaylists.com for inspiration. Also create a regular "iPod playlist" for those albums and tracks you just want to have on your iPod but can't think of a particular playlist they should be in. Just drag 'em in there so they'll sync to the iPod.

#3 Set your iPod to automatically update (entire library or just selected playlists) as opposed to manually managing it.

With these steps you'll be able to just grab the iPod and go. Plug in at night and unplug while you're running out the door. You won't even need to touch the computer. The iPod doesn't stay mounted on the desktop. IMHO this strategy is easiest and 100% automatic.



[ Reply to This | # ]
A one-keystroke iPod eject script
Authored by: Fofer on Sep 30, '04 12:15:24PM

I also use Doug's AppleScript to "Unmount-Mount iPod" when it's sitting in the FW cradle. That way I don't even have to physically remove it from dock to trigger an update after modifying playlists. Just invoke the script and it does the update for me!
http://www.malcolmadams.com/itunes/scripts/scripts08.php?page=2#mountipod



[ Reply to This | # ]
A one-keystroke iPod eject script
Authored by: ob1cannoli on Sep 30, '04 09:44:17PM

Control click your iPods icon in iTunes and click Update....no removal from dock required...



[ Reply to This | # ]
A one-keystroke iPod eject script
Authored by: mehrens on Dec 06, '04 11:38:03AM

what if my "enable disk use" option is greyed out ?? .. i'd like to uncheck it, but i can't, and the iPod mounts every time..

my goal is to just connect via firewire to charge, not mount..



[ Reply to This | # ]
Editor
Authored by: MJCube on Sep 30, '04 01:25:13PM

I for one appreciate the humorous editing in this hint. Thanks, robg, for a smile!



[ Reply to This | # ]
Ejector
Authored by: Anonymous on Sep 30, '04 02:03:32PM

You could also use Ejector :

http://www.jeb.com.fr/en/ejector.shtml

---
--
Thomas Deniau



[ Reply to This | # ]
A one-keystroke iPod eject script
Authored by: PeterDie on Sep 30, '04 03:08:49PM

I understand this keeping your iPod connected to a sleeping Mac is one sure fire way to destroy the battery. Or at least, the sleeping mac drains the iPod, and adds useless charging cycles to the iPod, rendering the battery prematurely weak. So poppin' your Pod out of the dock before sleeping would be the best course of action.



[ Reply to This | # ]
A one-keystroke iPod eject script
Authored by: DavidRavenMoon on Oct 01, '04 09:33:05AM

Keeping an iPod plugged into a sleeping Mac will drain the battery! I only connect mine to the computer when I update it. Otherwise I use the power adaptor with an extra cable for charging. That way I just unplug it in the morning and go! If I left it connected to my G4 I'd either have to leave the computer running all night, or wake it in the morning, which would both kill the battery and wake my wife! (since the Mac's in our bedroom).. and leaving the computer running all night is just a waste of energy and dumb.

---
--
G4/466, 1 GB, Mac OS X 10.3.5



[ Reply to This | # ]
A one-keystroke iPod eject script
Authored by: covvie on Oct 02, '04 04:50:43PM

I haven't had any problem with it on my Powerbook, but then the Powerbook is usually left plugged in to charge even when sleeping.

With the Powerbook sleeping and plugged in, the Powerbook continues to charge the iPod. I've not tried it with the Powerbook unplugged, since my assumption was it would drain the Powerbook's battery give the plugged in behavior.

Is this different than the desktop machines?



[ Reply to This | # ]
Ejector adds a nice icon as well...
Authored by: cyberbrent on Sep 30, '04 04:22:33PM
I use EJECTOR as well because it adds a nice like Eject icon to the Menu Bar. I also eject my digital camera with it. Its great. http://www.macupdate.com/info.php/id/12216 Regards Brent

---
"You alone define your limitations"

[ Reply to This | # ]

F-keys on Mac OS X
Authored by: gio on Sep 30, '04 05:17:39PM

Does anyone know how many F-keys are supported at maximum in OSX?

The F14 and F15 keys I have on the ADB keyboard (Apple Extended Keyboard II) of my B&W have no effect, and they aren't even listed on Exposè control panel... it stops at F13.



[ Reply to This | # ]
F-keys on Mac OS X
Authored by: sjmills on Sep 30, '04 10:33:48PM

Because Apple idiotically reserved them for 2 functions that almost nobody uses; decrease/increase brightness. That's incredibly selfish for 2 such wanna-be-assigned-to-other-stuff keys. I've submitted this as a bug, cuz it's just dumb.



[ Reply to This | # ]
F-keys on Mac OS X
Authored by: _merlin on Oct 01, '04 01:15:11AM

That's not true. I can use F-keys up to F15 on my Sun USB keyboard. The volume and power control keys on this keyboard work correctly, too.



[ Reply to This | # ]
F-keys on Mac OS X
Authored by: gio on Oct 03, '04 04:55:05PM

I made another test: also on a "Logitech Cordless Desktop Black Keyboard" I can only use keys until F13.

F14 and F15 has NO use. Where did you read they are assigned to brightness? On my Titanium F1 and F2 are reserved for brightness... :-/



[ Reply to This | # ]
Additional script available from Apple
Authored by: chaseter on Sep 30, '04 05:25:28PM

I found this script that comes bundled with the iPod scripts on the Apple site (http://www.apple.com/applescript/ipod/). Thought some of you might find it helpful...you could have this script launch with a keystroke as well. It is especially useful if you have two iPods. For instance, I have one 2G iPod as a firewire drive and my 3G for myMP3s and it would eject both upon the initiation of the script :)

Chase

begin applescript--->


try
display dialog "Eject iPod" & return & return & "This scirpt will attempt to eject the currently mounted iPod." buttons {"Cancel", "Continue"} default button 2

-- check for iPods
set the mounted_iPods to my locate_iPods()
-- check for iPod count
if the mounted_iPods is {} then
error "No iPod is connected to this computer."
else if the (count of the mounted_iPods) is greater than 1 then
-- choose iPod
set the ipod_names to {}
repeat with i from 1 to the count of the mounted_iPods
set this_iPod to item i of the mounted_iPods
tell application "Finder"
set the end of the ipod_names to the name of this_iPod
end tell
end repeat
set this_name to (choose from list ipod_names with prompt "Pick the iPod to use:") as string
if this_name is "false" then error number -128
repeat with i from 1 to the count of the ipod_names
if item i of the ipod_names is this_name then
set this_iPod to item i of the mounted_iPods
exit repeat
end if
end repeat
else
set this_iPod to item 1 of the mounted_iPods
end if

tell application "Finder"
eject this_iPod
end tell

display dialog "The iPod has been ejected." buttons {"•"} default button 1 giving up after 2
on error error_message number the error_number
if the error_number is not -128 then
display dialog error_message buttons {"OK"} default button 1
end if
end try

on locate_iPods()
set the volumes_directory to "/Volumes/" as POSIX file as alias
set the volume_names to list folder volumes_directory without invisibles
set mounted_iPods to {}
repeat with i from 1 to the count of volume_names
try
set this_name to item i of volume_names
set this_disk to ("/Volumes/" & this_name & "/") as POSIX file as alias
set these_items to list folder this_disk
if "iPod_Control" is in these_items then
set the end of the mounted_iPods to this_disk
end if
end try
end repeat
return mounted_iPods
end locate_iPods

<-- end applescript



[ Reply to This | # ]
Additional script available from Apple
Authored by: DougAdams on Oct 01, '04 08:13:04AM

This script is pretty much just a fancy version of the little one being discussed. AppleScripts from Apple have to account for many situations (to keep the support calls to a minimum, no doubt). This script will account for more than one iPod being mounted and get the correct name of the iPod, but in the end, it still just ejects the iPod like any other disk.



[ Reply to This | # ]
Who R U
Authored by: gourls on Sep 30, '04 08:27:13PM
Hey, how old are you? I'm twelve, and even though I don't really do AppleScripts yet, I am the type of person that would grab my iPod before running off to school. Good ideas. :)

---
-brita

[ Reply to This | # ]

A one-keystroke iPod eject script
Authored by: kainjow on Oct 01, '04 12:20:33AM
Or just use Pod2Go and setup scheduled syncing every morning and have it so it ejects your iPod after a sync :D

[ Reply to This | # ]
Yep, this is a no no...
Authored by: GORDYmac on Oct 04, '04 12:57:53PM

Keeping an iPod plugged in will KILL THE BATTERY.

Happened to me this morning.



[ Reply to This | # ]
Not necessarily?
Authored by: jiclark on Oct 05, '04 11:43:18AM

I'm surprised no one else has mentioned this, but I believe there are different behaviors based on different machines. I have a dual-2Gig G5, as well as an older G4/400. The G5 can keep charging the 'pod even when asleep, while the G4's FireWire ports seem to stop sending power when the machine sleeps. I just noticed this not too long ago, so I'm not positive about where the distinction lies, but thought it worth mentioning



[ Reply to This | # ]
A one-keystroke iPod eject script
Authored by: plobe on Oct 15, '04 05:47:55PM

OR http://www.versiontracker.com/dyn/moreinfo/macosx/20089



[ Reply to This | # ]