image
image

Go Back   macosx.com > Mac Help Forums > Unix & X11

Reply
 
LinkBack Thread Tools
  #1  
Old March 4th, 2003, 05:23 AM
profx's Avatar
ill never 4get watsisname
 
Join Date: May 2001
Location: Auckland New Zealand
Posts: 386
Thanks: 0
Thanked 0 Times in 0 Posts
profx is on a distinguished road
Question iTunes autoplay on wake - AppleScript help

well, slightly more complicated than that:

I have written two applescripts, one that is executed just before system sleep the other when the system wakes.

The first checks if itunes is running and if it is playing.
The second then resumes playing if itunes was playing before sleep.(notice the classy fade in)

on sleep: itunesSleep.scpt
Code:
try
	do shell script "top -l 1 | grep 'iTunes'"
	tell application "iTunes"
		if player state as string is "playing" then do shell script "/bin/echo play >~/itunesStatus.txt"
	end tell
end try
on wake: itunesWake.scpt
Code:
try
	tell application "iTunes"
		do shell script "/bin/cat ~/itunesStatus.txt"
		set stat to result as string
		set vol to sound volume as number
		set sound volume to 0
		if stat is "play" then play
		repeat with i from 1 to vol
			set sound volume to i
			set i to i + 1
			delay 0.4
		end repeat
		do shell script "/bin/rm ~/itunesStatus.txt"
	end tell
end try
these work perfectly when run from script editor but when run from terminal as
osascript -l Applescript itunesSleep.scpt
it packs a sad and fails to write the itunesStatus.txt file because the player status is
<<constant ****kPSP>> when run from terminal no matter what state the player is actually in.

Anyone have any ideas as to what is going on??

By the way i am planning on using sleepwatcher to run the scripts, but it can only run unix scripts, hence the need to use osascript.


Cheers.
__________________
| PowerBook G4 550 - 10.4 - 512Mb - 20Gb | 30Gb iPod Photo | 40x12x48 Fantom Drives CDRW (firewire) | Logitech Cordless Mouse MX700 | xBox with XBMC for movies and music in the lounge
Reply With Quote
  #2  
Old March 4th, 2003, 02:19 PM
profx's Avatar
ill never 4get watsisname
 
Join Date: May 2001
Location: Auckland New Zealand
Posts: 386
Thanks: 0
Thanked 0 Times in 0 Posts
profx is on a distinguished road
someone?
__________________
| PowerBook G4 550 - 10.4 - 512Mb - 20Gb | 30Gb iPod Photo | 40x12x48 Fantom Drives CDRW (firewire) | Logitech Cordless Mouse MX700 | xBox with XBMC for movies and music in the lounge
Reply With Quote
  #3  
Old March 16th, 2003, 11:20 PM
jove's Avatar
Member
 
Join Date: Nov 2000
Posts: 555
Thanks: 0
Thanked 0 Times in 0 Posts
jove is on a distinguished road
Is there anybody out there (PF)...

Tried it myself. Same problem. Looked on the ol' internet. Don't use string! playing is a usable constant. I changed the check routine to look for "playing". And I put a dot in front of the status file name.

tell application "iTunes"
if player state is playing then
do shell script "/bin/echo playing >~/.itunesStatus.txt"
else
do shell script "/bin/echo stopped >~/.itunesStatus.txt"
end if
end tell
__________________
Jove
Talk doesn't cook rice.

Last edited by jove; March 17th, 2003 at 12:13 AM.
Reply With Quote
  #4  
Old March 17th, 2003, 12:12 AM
jove's Avatar
Member
 
Join Date: Nov 2000
Posts: 555
Thanks: 0
Thanked 0 Times in 0 Posts
jove is on a distinguished road
The scripts work flawlessly. Sleep and wakeup do not.

The scripts are saved as applications in ~/Library/scripts. The .wakeup and .sleep scripts call "open ~/Library/Scripts/..."

The sleep application doesn't perform until wakeup. The wakeup application doesn't perform until a couple seconds later!

We need to be able to tell the system "Don't sleep until Applescript is done".
__________________
Jove
Talk doesn't cook rice.
Reply With Quote
  #5  
Old March 17th, 2003, 05:49 AM
profx's Avatar
ill never 4get watsisname
 
Join Date: May 2001
Location: Auckland New Zealand
Posts: 386
Thanks: 0
Thanked 0 Times in 0 Posts
profx is on a distinguished road
i have given up on getting the playing status of itunes before sleep, instead i just execute one script on wake up
Code:
tell application "Finder"
	if processes contains {process "iTunes"} then
		-- iTunes is running
		tell application "iTunes"
			set vol to sound volume as number
			set sound volume to 0
			back track
			play
			repeat with i from 1 to vol
				set sound volume to i
				set i to i + 1
				delay 0.4
			end repeat
		end tell
	end if
end tell
along with the shell script that executes the applecript

%osascript scriptname.scpt

dont forget to "chomd +x" your shell script file

This works perfectly for me.




on another note i often play my mac into a stereo so i find this script comes in handy:
Code:
tell application "Dock"
	activate
	display dialog "Choose Volume setting" buttons {"Stereo", "Normal"} default button 2
	set var to the button returned of the result
	if var is "Stereo" then
		tell application "iTunes"
			back track
			play
			set sound volume to 100
			set volume 10
		end tell
	else
		tell application "iTunes"
			next track
			play
			set sound volume to 15
			set volume 1
		end tell
	end if
end tell
it tells dock, so it dosent interupt your current app, eg telling finder would bring finder to the front and open a new window, telling dock leaves you in your current app.

An improvement to this script would be to get the system volume and check if full volume change to min volume, and visa versa
__________________
| PowerBook G4 550 - 10.4 - 512Mb - 20Gb | 30Gb iPod Photo | 40x12x48 Fantom Drives CDRW (firewire) | Logitech Cordless Mouse MX700 | xBox with XBMC for movies and music in the lounge
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[HOW TO] Autoplay itunes on wake profx HOWTO & FAQs 1 March 6th, 2003 06:03 PM
important iTunes install info zootbobbalu Apple News, Rumors & Discussion 15 July 19th, 2002 12:18 AM
iTunes 2 is going nuts! Bloated Temp Files! GadgetLover Mac OS X System & Mac Software 8 April 11th, 2002 05:45 PM
AppleScript, iTunes, Mp3 Tags, idea and problem jove Software Programming & Web Scripting 0 March 11th, 2002 05:03 PM
AppleScript to find iTunes songs with no Playlist rharder Apple News, Rumors & Discussion 0 December 29th, 2001 11:27 AM


All times are GMT -5. The time now is 08:37 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC1
Copyright 2000-2010 DigitalCrowd, Inc.