PDA

View Full Version : need help with itunes applescript




twoodcc
Feb 19, 2007, 01:06 PM
ok, i have taken some programming classes and stuff, but never anything with applescript.

i downloaded a script from here (http://www.dougscripts.com/itunes/scripts/scripts02.php) and the one i need help with is called 'Needle Drop'.

but i want to change it a little. instead of asking the user how many seconds and where to start playing, i want it to ask the user how many seconds, and then it start playing for that many seconds from the end of the track. does that make sense?

so, let's say you put in 10 seconds.....then it will play the last 10 seconds of the track.

thanks in advance



twoodcc
Feb 19, 2007, 03:11 PM
basically, how do you find the length of the track? this seems like it would be easy if you know the length of it, then whatever the user inputs, it subtracts it from the length...

twoodcc
Feb 19, 2007, 05:21 PM
well so far i have this:

global start_time
global needle

on run
tell application "iTunes"
activate
set needle to 5
set v to sound volume
copy 0 to sound volume
if selection is not {} then
play selection
else
play view of front window
end if
pause
copy v to sound volume

set start_time to time of current track
try
return (start_time as integer)
end try

set needle to start_time - needle
set player position to needle
play
end tell
end run
on quit
tell application "iTunes" to stop
continue quit
end quit

but i get the error " can't change 4:56 to number"
or something like that.

what can i do to fix it?

thanks

twoodcc
Feb 19, 2007, 05:56 PM
ok well i got it work! but how do i tell it to repeat until i quit the apple script?

twoodcc
Feb 19, 2007, 08:03 PM
ok well i got it work! but how do i tell it to repeat until i quit the apple script?

well i can get it to repeat, but how do i tell the script to pause for a number of seconds? (not pause itunes)

twoodcc
Feb 19, 2007, 09:08 PM
well i got my program to work! yea!

but only one problemo.....i can't get it to quit! i put 2 buttons on it, start and stop, but i can't click the stop button!

please help me here

global start_time
global needle



on clicked theObject
if title of theObject = "Start" then
repeat
tell application "iTunes"
activate
set needle to 5
set start_time to (duration of current track) - needle

set player position to start_time
play

end tell
delay 6
if title of theObject = "Stop" then
quit
end if
end repeat
else if title of theObject = "Stop" then
quit
end if

end clicked

on quit
tell application "iTunes" to stop
continue quit
end quit

twoodcc
Feb 19, 2007, 10:14 PM
well i finally got it to work! i just had to change quit to 'exit repeat' in one of the if statements.

when i start the program , i get an error message though, but it still works.

i'm kinda disappointed that no one helped me though

twoodcc
Feb 20, 2007, 08:40 PM
is there any way to make my program universal binary?

twoodcc
Feb 20, 2007, 09:24 PM
is there any way to make my program universal binary?

n/m, i figured it out on my own.....again ;) :apple:

lancestraz
Feb 20, 2007, 10:31 PM
To the OP: Good thing twoodcc was here to help you! You should thank him. :p

twoodcc
Feb 20, 2007, 10:44 PM
To the OP: Good thing twoodcc was here to help you! You should thank him. :p

LOL, you're right, i should :p

but he still couldn't help me fix the error that i get though. -1708 or something.

would love some help with that :):apple:

twoodcc
Feb 21, 2007, 12:26 AM
also, when i have my script going, i basically can't do anything else, b/c every time it repeats, it makes itunes come to the front. is there any way to make it run in the background, so i can use other applications at the same time?

thanks

bearbo
Feb 21, 2007, 12:36 AM
also, when i have my script going, i basically can't do anything else, b/c every time it repeats, it makes itunes come to the front. is there any way to make it run in the background, so i can use other applications at the same time?

thanks

don't put activate in the repeat

lancestraz
Feb 21, 2007, 09:50 AM
LOL, you're right, i should :p

but he still couldn't help me fix the error that i get though. -1708 or something.

would love some help with that :):apple:

also, when i have my script going, i basically can't do anything else, b/c every time it repeats, it makes itunes come to the front. is there any way to make it run in the background, so i can use other applications at the same time?

thanks

OK, OK. I'll try to help too.

In interface Builder, you need to add a "Wake from nib" event handler to the main window.
Then add this:
on awake from nib theObject
tell application "iTunes"
launch
end tell
end awake from nib
That should stop iTunes from jumping to the front.

As for the error. It's going sour because no song is playing in iTunes.
To solve that add this right inside the repeat > tell iTunes statement.
if selection is not {} then
play selection
else
play view of front window
end if

So in the end it should look like this:
global start_time
global needle

on clicked theObject
if title of theObject = "Start" then
repeat
tell application "iTunes"
if selection is not {} then
play selection
else
play view of front window
end if
set needle to 5
set start_time to (duration of current track) - needle
set player position to start_time
play
end tell
delay 6
end repeat
else if title of theObject = "Stop" then
quit
end if
end clicked

on awake from nib theObject
tell application "iTunes"
launch
end tell
end awake from nib

on quit
tell application "iTunes" to stop
continue quit
end quit

I also got rid of the:
"if title of theObject = "Stop" then
quit
end if"
that was inside the repeat loop. You don't need it.

twoodcc
Feb 21, 2007, 10:21 AM
don't put activate in the repeat

thanks :)

OK, OK. I'll try to help too.

In interface Builder, you need to add a "Wake from nib" event handler to the main window.
Then add this:
on awake from nib theObject
tell application "iTunes"
launch
end tell
end awake from nib
That should stop iTunes from jumping to the front.

As for the error. It's going sour because no song is playing in iTunes.
To solve that add this right inside the repeat > tell iTunes statement.
if selection is not {} then
play selection
else
play view of front window
end if

So in the end it should look like this:
global start_time
global needle

on clicked theObject
if title of theObject = "Start" then
repeat
tell application "iTunes"
if selection is not {} then
play selection
else
play view of front window
end if
set needle to 5
set start_time to (duration of current track) - needle
set player position to start_time
play
end tell
delay 6
end repeat
else if title of theObject = "Stop" then
quit
end if
end clicked

on awake from nib theObject
tell application "iTunes"
launch
end tell
end awake from nib

on quit
tell application "iTunes" to stop
continue quit
end quit

I also got rid of the:
"if title of theObject = "Stop" then
quit
end if"
that was inside the repeat loop. You don't need it.

thanks! i'll try it and let you know how it turns out. :) :apple:

twoodcc
Feb 21, 2007, 11:01 AM
well i still get the error, but it doesn't pop up itunes everytime now :) so i'm thankful for that.

i didn't take out the if statement like you did, so maybe that's the error. i'll try it when i get out of class

twoodcc
Feb 21, 2007, 11:48 AM
well using your method, i can't stop the program. i can't click the stop button, and i can't click the x at the top left. any ideas?

lancestraz
Feb 21, 2007, 02:09 PM
well using your method, i can't stop the program. i can't click the stop button, and i can't click the x at the top left. any ideas?
That's weird.
Try downloading this (http://mandarin.quickshareit.com/share/needle87423.zip). (my xcode project), and see if it works.

twoodcc
Feb 21, 2007, 03:07 PM
That's weird.
Try downloading this (http://mandarin.quickshareit.com/share/needle87423.zip). (my xcode project), and see if it works.

thanks, i'll try it and let you know :)

twoodcc
Feb 21, 2007, 03:45 PM
That's weird.
Try downloading this (http://mandarin.quickshareit.com/share/needle87423.zip). (my xcode project), and see if it works.

well yours works! i compared the two, and they are exactly the same, or seem to be. very weird. thanks though. i'm just glad it works :) :apple:

lancestraz
Feb 21, 2007, 04:01 PM
well yours works! i compared the two, and they are exactly the same, or seem to be. very weird. thanks though. i'm just glad it works :) :apple:
Maybe you forgot to tick some checkbox, or whatnot, in Interface Builder.
At least it works now. :)

twoodcc
Feb 21, 2007, 04:03 PM
Maybe you forgot to tick some checkbox, or whatnot, in Interface Builder.
At least it works now. :)

that's what i thought also, and i compared yours and mine, and they look the same for the buttons. maybe there's something somewhere else i forgot to look.

yeah, thanks :)