Re: Integration of Apple- and Tcl- script (Re: Applescript equivalent of $0 in shell script)
Re: Integration of Apple- and Tcl- script (Re: Applescript equivalent of $0 in shell script)
- Subject: Re: Integration of Apple- and Tcl- script (Re: Applescript equivalent of $0 in shell script)
- From: "Hiroshi T." <email@hidden>
- Date: Sun, 29 Oct 2006 14:18:39 +0900
Hello, Philip. I rewrote my Expect/Tcl script with Tclapplescript and
it became much faster than
the previous one. 'proc ReadAppleScript' is executed once at the start
up and the function 'macrem_iplay'
is called on every event from the USB device. Here is where I rewrote:
proc ReadAppleScript {} {
AppleScript execute {
property myStopTrackFile :
"~hrst/Library/iTunes/Scritps-Support/stop_track.lck"
on macrem_iplay(iComm0, next_track0)
set next_track to (next_track0 as number)
set iComm to (iComm0 as number)
-- do shell script "echo iComm=" & iComm & ",next_track=" &
next_track & " > /dev/console"
tell application "iTunes"
set rtVal to "nothing"
set iTstat to player state
if iTstat is paused or iTstat is stopped then
set rtVal to "paused"
if next_track is 1 then
if iComm is 1 then
say "next track"
next track
play
else
say "previous track"
previous track
play
end if
else
if iComm is -1 then
say "rewind"
try
do shell script "test -f " & myStopTrackFile
previous track
previous track
end try
set player position to 0
end if
play
end if
else if iTstat is playing then
set rtVal to "playing"
if iComm is 1 then
pause
tell application "iTunes_Monitor"
remember_current_playlist()
end tell
else
set secondsToRewind to 30
set pos to player position
if (pos is greater than secondsToRewind) and (pos is less than
finish of current track) then
set player position to pos - secondsToRewind
play
else
set player position to 0
end if
end if
else
playpause
end if
end tell
try
do shell script "rm -f " & myStopTrackFile
end try
return (rtVal as string)
end macrem_iplay
}
}
proc iPlay {iComm} {
global iTunes_status
global next_track
global downward
global cur_track
global prev_track
global timeout
DbgMsg 1 "next_track = $next_track"
set iTunes_status "nothing"
#set iTunes_status [exec sh -c "/usr/bin/osascript -e 'tell
application \"iTunes_Monitor\" to return macrem_iplay($iComm,
$next_track)'"]
catch {set iTunes_status [AppleScript execute
"macrem_iplay($iComm,$next_track)"]}
regsub -all "\"" $iTunes_status "" iTunes_status
DbgMsg 2 "iTunes Status = $iTunes_status"
if {"$iTunes_status" == "paused" } {
set timeout [expr 60 * 60]
DbgMsg 2 "Setting timeout to $timeout"
set next_track 0
} elseif {"$iTunes_status" == "playing" } {
if {$iComm == 1} {
set timeout 10
DbgMsg 2 "Setting timeout to $timeout"
set next_track 1
}
} else {
#DbgMsg 2 "You cannot come here!"
set timeout -1
set next_track 0
}
}
---
H.T.
Any mail that does not come from this mailing list is ignored.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden