Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface 如何通过AppleScript判断iPod同步何时完成_User Interface_Applescript_Itunes - Fatal编程技术网

User interface 如何通过AppleScript判断iPod同步何时完成

User interface 如何通过AppleScript判断iPod同步何时完成,user-interface,applescript,itunes,User Interface,Applescript,Itunes,我正在尝试制作一个AppleScript,它将同步并弹出我的iPod,而无需在脚本启动后提供任何输入。基本脚本是: set ipodList to {} tell application "iTunes" try set ipodList to (name of every source whose kind is iPod) end try repeat with ipodName in ipodList update ipodName

我正在尝试制作一个AppleScript,它将同步并弹出我的iPod,而无需在脚本启动后提供任何输入。基本脚本是:

set ipodList to {}
tell application "iTunes"
    try
        set ipodList to (name of every source whose kind is iPod)
    end try
    repeat with ipodName in ipodList
        update ipodName
        eject ipodName
    end repeat
end tell
该脚本的问题在于,它会导致iTunes在同步开始后立即尝试弹出iPod,因此同步尚未完成。这有时会导致出现一个或两个对话框窗口。一个窗口显示“iTunes正在同步iPod。您确定要弹出它吗?”并有两个按钮,“取消”和“弹出”。另一个窗口显示“iPod“nanoBot”无法弹出,因为它包含其他应用程序正在使用的文件。”并且只有一个“确定”按钮。只需单击“弹出”和“确定”即可使iTunes完成对iPod的同步,然后将其弹出

我想使用UI脚本来点击这两个按钮,这样iTunes就可以做我想做的事情。事实上,以下脚本似乎符合我的要求:

tell application "System Events"
    tell process "iTunes"
        try
            click button "Eject" of window 1
        end try
        try
            click button "OK" of window 1
        end try
    end tell
end tell
然而,我通过从第二个AppleScript运行第二位代码来测试它。第一个AppleScript的执行挂起在eject命令上,直到我点击两个对话框为止(如果它挂起在update命令上,所有这些麻烦都会解决…)

是否有任何方法可以通过与弹出命令相同的脚本单击对话框?或者从第一个Applescript启动第二个Applescript,让它不断检查这些对话框窗口是否出现,然后单击它们?还是有更简单的方法来解决这个问题

[编辑:我应该补充一点,我目前所做的只是用update命令同步iPod,暂停几秒钟,然后用Finder弹出iPod(我已将其设置为磁盘驱动器)。此方法的问题是无法判断同步何时完成,如果未完成,则脚本不会弹出iPod并引发错误。]

请尝试此

set ipodList to {}
tell application "iTunes"
  try
    set ipodList to (name of every source whose kind is iPod)
end try
repeat with ipodName in ipodList
    update ipodName
    tell me to wait_for_sync()
eject ipodName  
end repeat
end tell

on wait_for_sync()
tell application "System Events" to tell application process "iTunes"
    set theStatusText to ""
    repeat until theStatusText is "iPod sync is complete."
        set theStatusText to value of static text 1 of scroll area 1 of window "iTunes"
        delay 1
    end repeat
end tell
end wait_for_sync
试试这个

set ipodList to {}
tell application "iTunes"
  try
    set ipodList to (name of every source whose kind is iPod)
end try
repeat with ipodName in ipodList
    update ipodName
    tell me to wait_for_sync()
eject ipodName  
end repeat
end tell

on wait_for_sync()
tell application "System Events" to tell application process "iTunes"
    set theStatusText to ""
    repeat until theStatusText is "iPod sync is complete."
        set theStatusText to value of static text 1 of scroll area 1 of window "iTunes"
        delay 1
    end repeat
end tell
end wait_for_sync

事实上,我发现如果我用Finder而不是iTunes弹出,我可以点击对话框窗口,但是这个解决方案要好得多!事实上,我发现如果我用Finder而不是iTunes弹出,我可以点击对话框窗口,但是这个解决方案要好得多!