【问题标题】:Change desktop app icons on mac, programatically. 2019以编程方式更改 Mac 上的桌面应用程序图标。 2019
【发布时间】:2019-07-07 08:51:26
【问题描述】:

有没有一种方法可以更改 Macbook 桌面应用程序上的图标,以复制在查找器窗口中复制/粘贴图标时发生的相同操作?通过终端、node.js 还是其他方式?到目前为止我已经尝试过:

1)通过终端,删除和替换图标本身,我不喜欢这样,因为它完全删除了原始图标​​,并且不适用于每个应用程序。

2)通过node.js和终端,创建一个图标?文件,但是这也不适用于每个程序,而且我在权限访问方面遇到了麻烦。如果有人对此有解决方案,我想听听。

3) 使用applescript,这很有效,但是一次循环遍历多个图标对它来说太过分了。

我已经搜索了几天,但信息要么非常有限,要么已经过时。我将不胜感激任何帮助!

【问题讨论】:

    标签: node.js macos shell electron desktop-application


    【解决方案1】:

    为了更改应用程序的图标,我使用带有 applescript 的 shell 脚本。 目标是更改应用程序 info.plist 中的“图标文件”并复制应用程序资源中的图标(文件)。 “应用程序”.app/Contents/Resources/“。 一切都在一个小滴中完成,我在其上拖动所需的图标,然后打开一个窗口以选择必须更改其图标的应用程序。 使用 plutil 我将文件 info.plist 转换为 xml1(我将其保存在“.app/Contents/infoo.plist”下以避免任何问题并找到原始文件)。要更改值“图标文件”,我使用“/usr/libexec/PlistBuddy”和“-c Set:” 要查看更改,您必须启动应用程序(其图标已更改),在 Dock 中您必须看到新图标(如果 Dock 选项处于活动状态)

    droplet 脚本下方

        global testdir
    on open draggedItems
        repeat with currentItem in draggedItems
            set icon_image_file_string to POSIX path of (draggedItems)
            set {name:Nm, name extension:Ex} to info for POSIX file icon_image_file_string
            set Nm to do shell script "echo " & Nm & " | sed 's#." & Ex & "##'"
    
            set testdir to POSIX path of (choose file of type {"APPL"} with prompt "Choisissez  l'Application pour changer son icone  :")
            set {name:Nmm, name extension:Ex} to info for POSIX file testdir
    
            do shell script "plutil -convert xml1 " & quoted form of (testdir & "Contents/Info.plist ") & " | cat " & quoted form of (testdir & "Contents/Info.plist") & " >" & quoted form of (testdir & "Contents/Infoo.plist")
            try
                do shell script "cp -f " & quoted form of icon_image_file_string & " " & quoted form of (testdir & "Contents/Resources/")
            end try
            try
                set icon_image_file to do shell script "/usr/libexec/PlistBuddy   " & quoted form of (testdir & "Contents/Info.plist") & " -c \"Set:CFBundleIconFile " & Nm & "\""
            end try
        end repeat
    end open
    

    【讨论】:

      猜你喜欢
      • 2011-07-24
      • 2014-03-07
      • 1970-01-01
      • 2012-08-17
      • 1970-01-01
      • 2013-08-12
      • 2023-03-16
      相关资源
      最近更新 更多