【问题标题】:AppleScript -- How to change the default Printer based on networkAppleScript -- 如何根据网络更改默认打印机
【发布时间】:2010-02-11 23:37:48
【问题描述】:

我想制作一个将在我的计算机上运行的应用程序,该应用程序将通过 AppleScript 更改“系统偏好设置”的“打印机和传真”偏好设置窗格中的“默认打印机”?

我希望它根据我所在的无线网络更改打印机。如果需要,我会退出并从每次网络更改开始,但理想情况下,我希望它自动为我完成。

我该怎么做呢?如果您需要 IP 地址、网络名称和/或打印机名称,请发表评论并告诉我。我想让它在 3 台打印机之间切换,我想让它在 3 个无线网络之间切换。

谢谢!

【问题讨论】:

    标签: applescript


    【解决方案1】:

    这样的事情会让你开始抓取当前位置。您需要在更改位置时触发此操作,然后一旦它获取位置,您将需要一个 if else 语句来遍历您的不同打印机。 MacScripter 是 Applescript 帮助的好地方;有人可能已经完成了您想做的事情:MacScripter。还有一些方法可以在 shell 中获取网络位置,这会比 Applescript 更快。

    还有MarcoPolo - Context-aware computing for Mac OS X,一款无需编写 Applescript 即可完成您想做的事情的应用。

    tell application "System Preferences"
       activate
    end tell
    
    tell application "System Events"
       tell application process "System Preferences"
           set frontmost to true
           click menu item "Network" of menu "View" of menu bar 1
    --you may need a delay here, adjust to suit
    delay 1
           set machineLocation to value of pop up button 1 of window "Network"
       end tell
    end tell
    tell application "System Preferences" to quit
    

    【讨论】:

    • 是的,我在 MacScripter 上发了一个帖子,但程序不起作用,当我回复时没有人回答,所以我想我会尝试一下。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-21
    • 2018-02-05
    • 2011-02-05
    • 2014-03-16
    • 1970-01-01
    相关资源
    最近更新 更多