代码之家  ›  专栏  ›  技术社区  ›  Nathan S.

Applescript取消对计算机的iTunes授权

  •  1
  • Nathan S.  · 技术社区  · 14 年前

    我有一台授权通过iTunes播放音乐的计算机(Mac),我想禁用它。但是,我只能通过ssh访问机器。是否有一个我可以远程运行(例如通过终端)的applescript,我可以使用它来取消对机器的授权?

    我知道我可以未经授权使用我授权的所有机器,但如果可能的话,我更愿意使用此解决方案。

    1 回复  |  直到 14 年前
        1
  •  2
  •   user225057user225057    14 年前

    我在iTunes字典中看不到任何授权/取消授权的属性,但我只是玩了GUI脚本,想出了一个解决方案。因此,目标Mac必须启用GUI脚本才能使下面的脚本工作。

    tell application "System Events"
    tell process "iTunes"
        click menu item "Deauthorize This Computer…" of menu 1 of menu bar item "Store" of menu bar 1
        delay 1
        set frontmost to true
        click menu 1 of menu bar item "Store" of menu bar 1
        set value of text field 1 of window "Deauthorize This Computer" to "password"
        click button "Deauthorize" of window "Deauthorize This Computer"
    end tell
    end tell
    

    您可以将AppleScipt留在目标Mac上,然后使用open命令启动它。或者您可以复制上面的AppleScript并将其粘贴到shell脚本中,并对osascript使用HEREDOC方法。

    完整的例子如下:

    osascript<<END 
    tell application "System Events"
    tell process "iTunes"
        click menu item "Deauthorize This Computer…" of menu 1 of menu bar item "Store" of menu bar 1
        delay 1
        set frontmost to true
        click menu 1 of menu bar item "Store" of menu bar 1
        set value of text field 1 of window "Deauthorize This Computer" to "password"
        click button "Deauthorize" of window "Deauthorize This Computer"
     end tell
     end tell
    END
    

    上述方法同样适用于Apple远程桌面的Send Unix功能。

    另外,请注意密码包含在这个脚本中,我不建议 但这是需要在解除授权窗口。如果在脚本中输入密码,请确保该脚本安全,这样就不会有人知道您的苹果密码。