V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
CupTools
V2EX  ›  问与答

有谁也用AppleScript的?

  •  
  •   CupTools · 2011-02-27 16:06:21 +08:00 · 3760 次点击
    这是一个创建于 5037 天前的主题,其中的信息可能已经有所发展或是发生改变。
    突然想获取iTunes的Now Playing,然后就找了下资料,结果发现,AppleScript是非常好用的

    获取Now Playing:
    try
    tell application "Finder"

    if (get name of every process) does not contain "iTunes" then
    set output to "iTunes is not active"
    else
    tell application "iTunes"
    if player state is not playing then
    set output to "iTunes is not playing"
    else
    set art to artist of current track as string
    set tra to name of current track as string
    set alb to album of current track as string
    set output to tra & " [" & alb & "] by " & art
    end if
    end tell
    end if
    end tell
    on error
    set output to "An unexpected error has occurred"
    end try

    使用Growl提醒:
    set AppName to "AppleScript Growl"
    set NotifyName to "Everything"

    on doRegister() --YOU NEED TO REGISTER FIRST!
    global AppName, NotifyName
    tell application "GrowlHelperApp"
    set the enabledNotificationsList to {NotifyName}
    register as application AppName all notifications enabledNotificationsList default notifications enabledNotificationsList
    end tell
    end doRegister

    on doNotify(title, desc)
    global AppName, NotifyName
    set titleToNotify to title
    set descToNotify to desc
    tell application "GrowlHelperApp"
    notify application name AppName with name NotifyName title titleToNotify description descToNotify
    end tell
    end doNotify

    on doNotifyWithIcon(title, desc, useapp)
    global AppName, NotifyName
    set titleToNotify to title
    set descToNotify to desc
    set iconToNotify to useapp
    tell application "GrowlHelperApp"
    notify application name AppName with name NotifyName title titleToNotify description descToNotify icon of application iconToNotify
    end tell
    end doNotifyWithIcon

    set output to ""

    真的很爽很爽.....
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2703 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:22 · PVG 22:22 · LAX 06:22 · JFK 09:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.