1

何が間違っているのかわかりません。NSTimerの使い方もわかりません...[実行]をクリックすると、単純なアプリを実行したいだけです...スクリプトの一部がループします(これが私です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は実行ボタンに関連付けられています...実行ボタンをクリックすると、ループが1回トリガーされますが、その後停止します... runOLEDWMESERIAL_(sender)のすべてに繰り返しを追加すると、delay(1)が機能します。しかし、UIで応答しなくなり、停止できません...それで、NSTimerが機能しない理由を誰かが理解するのを手伝ってくれるでしょうか

4

1 に答える 1

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_
于 2013-03-21T04:07:00.650 に答える