ok, so in my new iTunes controller it is alot smaller so i had no room for a FF button and a skip track button so i’m trying to make a button like in itunes where if you click it it skips track and if you hold it fast forwards/rewinds until you let go in which it resumes playing. I almost got it to work except when it was fast forwarding when you let go it skipped to the next track! UNCOOL!
EDIT: also wondering if there is a way to make text that is too long to scroll like in itunes
I don’t know if this is the official way to handle sustained vs brief clicks, but it works:
(Obviously omit the ‘display dialog’ entries - they are there just to make it easier to test the routines by themselves)
on mouse down theObject event theEvent
global StartTimer, DelayTime
set DelayTime to 0.2 -- Change this to determine how long user can hold button down for and still be counted as a 'click' vs 'holding mouse down'
if name of theObject = "Fwd" then set StartTimer to time of (current date)
tell application "iTunes" to fast forward
end mouse down
on mouse up theObject event theEvent
global StartTimer, DelayTime
if name of theObject = "Fwd" then set TimeDiff to (time of (current date)) - StartTimer
if TimeDiff is less than DelayTime then
tell application "iTunes" to next track
display dialog "I'll treat that as a click " giving up after 1
else
tell application "iTunes" to resume
display dialog "I'll treat that as held down" giving up after 1
end if
end mouse up
As for scrolling text messages, what about trying:
http://www.applescript.net/viewtopic.php?id=4846
hmm…the rewind button works but when i hit the fast forward/skip track it goes back to the start of the track. Heres the mouseup/mousedown code:
on mouse down theObject event theEvent
global StartTimer, DelayTime
set DelayTime to 0.2 -- Change this to determine how long user can hold button down for and still be counted as a 'click' vs 'holding mouse down'
if name of theObject is equal to "next_button" then set StartTimer to time of (current date)
tell application "iTunes" to fast forward
if name of theObject is equal to "prev_button" then set StartTimer to time of (current date)
tell application "iTunes" to rewind
end mouse down
on mouse up theObject event theEvent
global StartTimer, DelayTime
if name of theObject is equal to "next_button" then set TimeDiff to (time of (current date)) - StartTimer
if TimeDiff is less than DelayTime then
tell application "iTunes" to next track
else
tell application "iTunes" to resume
end if
if name of theObject is equal to "prev_button" then set TimeDiff to (time of (current date)) - StartTimer
if TimeDiff is less than DelayTime then
tell application "iTunes" to back track
else
tell application "iTunes" to resume
end if
end mouse up
Hendo,
You need to have a careful look at the contents of your if…then statements:
- Make sure that everything you want to happen in your ‘if’ comes before then else or end if
For example - in ‘mouse down’ you were telling iTunes to fast forward and then to rewind, neither of which were in an if/end if block, so it was doing both!
- Be careful to not to call variables that have only been defined in an if/end if block: in the instances where the ‘if…’ criteria were not met, the variable will have be undefined, and you will generate an error.
For example - in your ‘mouse up’ routine, you defined TimeDiff ‘if’ name of theObject = “next_button”. This is OK in the instances in which only 1 object makes a call to the handler (but then the name of the object is known anyway!). However, you then go on to compare TimeDiff to DelayTime, but the former will not be defined if the button pressed was “prev_button”
In short you need to:
- Capture your “fast forward” / “rewind” commands and “next track” / “back track” within the appropriate ‘if…then’ statements
- Define TimeDiff without any conditions, i.e. near the start of the ‘mouse up’ handler. (You could do the same with the StartTime variable in the ‘mouse down’ handler.)
I have the appropriate code - let me know if you struggle to make sense of this or to make it work.
well, i have tried about 10 times now…so i am legitemetly strugglin’ now:(
OK, here’s what I’m using.
Hope it works for you.
on mouse down theObject event theEvent
global StartTimer, DelayTime
set DelayTime to 0.2 -- Change this to determine how long user can hold button down for and still be counted as a 'click' vs 'holding mouse down'
-- However, I suspect that the time difference is only measured in whole seconds anyway!
set StartTimer to time of (current date)
if name of theObject is equal to "next_button" then tell application "iTunes" to fast forward
if name of theObject is equal to "prev_button" then tell application "iTunes" to rewind
end mouse down
on mouse up theObject event theEvent
global StartTimer, DelayTime
set RFButtons to {"next_button", "prev_button"}
set TimeDiff to (time of (current date)) - StartTimer
if TimeDiff is greater than DelayTime and RFButtons contains (name of theObject) then
tell application "iTunes" to resume
else if name of theObject is equal to "next_button" then
tell application "iTunes" to next track
else if name of theObject is equal to "prev_button" then
tell application "iTunes" to back track
end if
end mouse up
works like a charm! thank you!!!