终端命令在登录时打开应用程序

问题描述 投票:-2回答:1

我已经使用AppleScript为朋友创建了一个恶作剧应用程序。我唯一没想到的是如何更改应用程序内容以使应用程序在登录时自动打开。我可以使用特定的info.plist密钥吗?

如果不是,如何在运行时让应用程序更改计算机设置,以便在登录时打开应用程序?

这是我在应用程序中添加的脚本。这是一个stay-open应用程序。

   property idleTime : 10 --seconds


on run

    idle

end run


on idle

    tell application "Google Chrome"
        if it is not running then return idleTime

        tell window 1 to if it exists then ¬
            tell its active tab
                set its URL to "chrome://newtab/"
            end tell
    end tell

    return idleTime

end idle
login terminal applescript
1个回答
0
投票

要使应用程序在系统启动时启动,您可以转到系统首选项>用户和组;选择合适的用户;然后选择登录项目。你会看到这样的屏幕:

Login Items on MacOS

单击+按钮,然后选择要添加到列表中的应用程序。您可能还希望选中该复选框以隐藏应用程序,以便它不会弹出屏幕。但是,这不会将其隐藏在码头之外。

如果您确实需要以任何方式以编程方式设置它,则可以使用AppleScript执行此操作。例如,如果我想将Calendar.app添加到启动项列表中,我将运行以下命令:

    tell application "System Events" to ¬
        make new login item with properties ¬
        {name:"Calendar", path:"/Applications/Calendar.app", hidden:true}

要从终端执行此操作,您将使用osascript运行相同的命令,如下所示:

    osascript -e 'tell application "System Events" to ¬' \
              -e 'make new login item with properties ¬' \
              -e '{name:"Calendar", path:"/Applications/Calendar.app", hidden:true}'
© www.soinside.com 2019 - 2024. All rights reserved.