从Mac Dock隐藏正在运行的应用程序而不影响应用程序的UI(不使用LSUIElement = TRUE)

问题描述 投票:0回答:1

我编写了一个AppleScript小程序,用于检查自定义发票程序的上次手动备份日期。在警告用户之后,该备份(并询问他们是否现在要备份)了,该备份将运行实际的发票程序。我给它提供了与主程序相同的图标,一个相似的名称,然后用我的跑步者替换了停靠图标。

除了运行程序运行“真实”程序之后,一切正常,我剩下两个Dock图标(运行程序和运行的“真实”程序)。

我本来的想法是禁止真实程序在Dock中显示,并让跑步者继续运行。我编辑了真实程序info.plist,将其隐藏在扩展坞中(LSUIElement = TRUE),但这似乎也隐藏了菜单栏,最小化以及关闭图标。

任何人都可以提出一种方法,使我仅拥有1个Dock图标,并使其指示程序是否正在运行。

macos applescript hide dock
1个回答
0
投票

我将以下两行添加到应用程序的info.plist文件中。这样做会在应用程序运行时将其图标从扩展坞中隐藏(只要在运行时该图标尚未位于扩展坞中即可。),在运行时使该应用程序的菜单项可见。

<key>LSBackgroundOnly</key>
<false/>

这里是我编写的AppleScript实用程序,它允许您选择一个应用程序以从扩展坞中隐藏其图标。如果应用程序已从扩展坞中隐藏,则此脚本将为您提供取消隐藏它的选项。

property fileTypes : {"com.apple.application-bundle"}
property plistFileItem : "  <key>LSBackgroundOnly</key>" & linefeed & " <true/>"

activate
set chosenApp to (choose application with prompt ¬
    "Choose  The Application You Want Hidden From The Dock While It Is Running" as alias)

tell application "System Events" to set appName to name of chosenApp
set plistFile to ((POSIX path of chosenApp) & "/Contents/info.plist") as string
set plistFileContents to (read plistFile)
set plistFileItemExists to plistFileItem is in plistFileContents

if plistFileItemExists then
    activate
    set theChoice to button returned of (display dialog ¬
        "Would you like to un-hide " & quote & appName & quote & ¬
        " from the Dock while it's running?" buttons {"Cancel", "Un-Hide"} ¬
        default button 2 cancel button 1 with title "Make A Choice")
else
    activate
    set theChoice to button returned of (display dialog ¬
        "Would you like to hide " & quote & appName & quote & ¬
        " from the Dock while it's running?" buttons {"Cancel", "Hide"} ¬
        default button 2 cancel button 1 with title "Make A Choice")
end if

if theChoice is "Hide" then
    tell application "System Events" to tell contents of property list file plistFile ¬
        to make new property list item at end with properties ¬
        {kind:string, name:"LSBackgroundOnly", value:true}
else if theChoice is "Un-Hide" then
    tell application "System Events" to tell contents of property list file plistFile ¬
        to make new property list item at end with properties ¬
        {kind:string, name:"LSBackgroundOnly", value:false}
else
    return
end if

enter image description hereenter image description hereenter image description here

© www.soinside.com 2019 - 2024. All rights reserved.