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

Stop and restart a selected iTunes track via scripts UNIX
I have my computer set to wake me up with an audio book, and to remember the spot that it stopped at on the previous day. This is accomplished by using CronniX to run two Bash scripts that utilize the command osascript. The scripts are as follows:

In a file called book_op, enter this code:

#!/bin/sh
#
osascript -e "set volume 5"
open -a iTunes "$(cat ~/book_tn.txt)"
In a file called book_cl, enter the following code. Important note: The first osascript line below has been split into three lines for easier viewing here on macosxhints. Enter it as one long line, replacing each line break with a single space!
#!/bin/sh
#
osascript -e 'tell application "iTunes" to set floc to 
  (get location of current track)' -e 
  'set ufloc to POSIX path of floc' > ~/book_tn.txt
osascript -e 'tell application "iTunes" to stop' 
The book_op script first sets the system volume to a reasonable level, so I wake and the neighbors don't. Next it opens the last track that was playing when the book_cl script was last run on the previous day. When the second script is run, the location of the current track is converted to a UNIX path and then saved it to a text file in your home directory called book_tn.txt. Then the script tells iTunes to stop. Save the scripts in two different files somewhere in your path, then type in terminal (the % should not be typed):
% chmod 755 book_op  
% chmod 755 book_cl
This makes them executable files. Then open iTunes and find and play the current track that you want to hear when you wake up. Then in Terminal type book_cl. This should create the file book_tn.txt in your home directory and stop iTunes. Next check to see if it worked by typing book_op. This should start iTunes at the track you were just playing. Finally, use CronniX to set book_op to run at a good time to wake up, and book_cl to run at a good time to be out the door. Enjoy!

[robg adds: I don't have any audio books, but the scripts worked as described for a song file (though it won't remember the stop point in a song).]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[5,791 views]  

Stop and restart a selected iTunes track via scripts | 2 comments | Create New Account
Click here to return to the 'Stop and restart a selected iTunes track via scripts' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Stop and restart a selected iTunes track via scripts
Authored by: DougAdams on Dec 03, '04 10:53:58AM
Rip your audiobooks as AAC and run Make Bookmarkable to make your files, well, bookmarkable.

[ Reply to This | # ]
Stop and restart a selected iTunes track via scripts
Authored by: vipm on Aug 05, '09 10:56:50AM

In the latest iTunes (I'm using 8.2), there's no longer need for this. Just select your mp3 or whatever audio files, click Cmd+i (info) and go to Options tab then pick "Remember Position: Yes". For good measure, you can also set "MediaKind:" to "Audiobook".



[ Reply to This | # ]