我不确定我做错了什么,我也不知道如何使用NSTimer ...我只是想运行一个简单的应用程序,当你点击Run ...它会循环一部分脚本(这个是我试图让NSTimer做的,然后当你点击停止...它停止
到目前为止,我有这个......
current application's NSTimer's timerWithTimeInterval_target_selector_userInfo_repeats_(1, me, "runOLEDWMESerial:", missing value, yes)
on runOLEDWMESerial_(sender)
set player_active to false
set theString to "Error;00:00:00:00"
tell application "Finder"
if (get name of every process) contains "NicePlayer" then set player_active to true
end tell
if player_active then
try
tell application "NicePlayer"
if ((count of movies) is not 0) then
tell front playlist
set theName to name
set curSeconds to elapsed time as integer
set theSeconds to duration as integer
set theHours to theSeconds div 3600
set theSeconds to theSeconds - theHours * 3600
set theMinutes to theSeconds div 60
set theSeconds to theSeconds - theMinutes * 60
set theDuration to ""
if theHours > 0 then
if theHours < 10 then set theHours to "0" & theHours
set theDuration to theHours & ":"
end if
if theMinutes < 10 then set theMinutes to "0" & theMinutes
if theSeconds < 10 then set theSeconds to "0" & theSeconds
set theDuration to theDuration & theMinutes & ":" & theSeconds
set curHours to curSeconds div 3600
set curSeconds to curSeconds - curHours * 3600
set curMinutes to curSeconds div 60
set curSeconds to curSeconds - curMinutes * 60
set curTime to ""
if curHours > 0 then
if curHours < 10 then set curHours to "0" & curHours
set curDuration to curHours & ":"
end if
if curMinutes < 10 then set curMinutes to "0" & curMinutes
if curSeconds < 10 then set curSeconds to "0" & curSeconds
set curTime to curTime & curMinutes & ":" & curSeconds
set theString to theName & ";" & curTime & ";" & theDuration
end tell
end if
end tell
on error errmsg
set theString to "Error2;00:00;00:00"
end try
end if
textName's setStringValue_(theName)
textTime's setStringValue_(curTime & "/" & theDuration)
end runOLEDWMESerial_
是的我确定我的代码很难看,但实际上这将是通过串口发送数据,这是主要目标,但是现在我只是想让窗口回显正在播放的内容。 ..
所以runOLEDWMESerial绑定到一个运行按钮...当你单击运行按钮时,循环触发一次,但然后停止...如果我在runOLEDWMESERIAL_(发送者)的所有内容中添加一个重复延迟(1)它有效,但在ui中也没有响应,我无法阻止它......所以有人可以帮助我理解为什么NSTimer无法正常工作
答案 0 :(得分:0)
我实际上已经明白了......我有它的后缀...... runOLEDWMESerial_是按钮......但是如果你这样做的话......我还必须删除try部分,因为它不允许它工作正常
on ClickButton_(sender)
current application's NSTimer's timerWithTimeInterval_target_selector_userInfo_repeats_(1, me, "runOLEDWMESerial:", missing value, yes)
end Clickbutton_
on runOLEDWMESerial_()
set player_active to false
set theString to "Error;00:00:00:00"
tell application "Finder"
if (get name of every process) contains "NicePlayer" then set player_active to true
end tell
if player_active then
tell application "NicePlayer"
if ((count of movies) is not 0) then
tell front playlist
set theName to name
set curSeconds to elapsed time as integer
set theSeconds to duration as integer
set theHours to theSeconds div 3600
set theSeconds to theSeconds - theHours * 3600
set theMinutes to theSeconds div 60
set theSeconds to theSeconds - theMinutes * 60
set theDuration to ""
if theHours > 0 then
if theHours < 10 then set theHours to "0" & theHours
set theDuration to theHours & ":"
end if
if theMinutes < 10 then set theMinutes to "0" & theMinutes
if theSeconds < 10 then set theSeconds to "0" & theSeconds
set theDuration to theDuration & theMinutes & ":" & theSeconds
set curHours to curSeconds div 3600
set curSeconds to curSeconds - curHours * 3600
set curMinutes to curSeconds div 60
set curSeconds to curSeconds - curMinutes * 60
set curTime to ""
if curHours > 0 then
if curHours < 10 then set curHours to "0" & curHours
set curDuration to curHours & ":"
end if
if curMinutes < 10 then set curMinutes to "0" & curMinutes
if curSeconds < 10 then set curSeconds to "0" & curSeconds
set curTime to curTime & curMinutes & ":" & curSeconds
set theString to theName & ";" & curTime & ";" & theDuration
end tell
end if
end tell
end if
textName's setStringValue_(theName)
textTime's setStringValue_(curTime & "/" & theDuration)
end runOLEDWMESerial_