在 Mac 应用程序中使用 Applescript 隐藏桌面图标

发布于 2025-01-12 02:48:00 字数 1483 浏览 3 评论 0原文

我有以下苹果脚本来隐藏桌面图标,当它独立运行时它可以正常工作。

on run
   do shell script "chflags hidden ~/Desktop/*"
end run

目标:通过点击 mac 应用程序中的按钮来隐藏桌面图标,因此我使用 swift 在 mac 应用程序中编写了 applescript 代码。

func hideDesktopIcons() {
        
        let source = """
        on run
            do shell script "chflags hidden ~/Desktop/*"
        end run
        """

        let script = NSAppleScript(source: source)!
        var error: NSDictionary?
        script.executeAndReturnError(&error)
        
        if let error = error {
            print(error)
        }
    }

我还确保设置了以下键 1

在此处输入图像描述

结果:

{
    NSAppleScriptErrorAppName = "Focus";
    NSAppleScriptErrorBriefMessage = "chflags: /Users/deepu/Library/Containers/com.deepu.Focus/Data/Desktop/*: No such file or directory";
    NSAppleScriptErrorMessage = "chflags: /Users/deepu/Library/Containers/com.deepu.Focus/Data/Desktop/*: No such file or directory";
    NSAppleScriptErrorNumber = 1;
    NSAppleScriptErrorRange = "NSRange: {3, 53}";
}

我已阅读此内容,但似乎根本不起作用 隐藏Mac OS下的所有桌面图标

I've this following applescript to hide desktop icons that works fine when it run it standalone.

on run
   do shell script "chflags hidden ~/Desktop/*"
end run

Goal: Hide desktop icons by tapping a button from a mac app, so I wrote the applescript code in mac app using swift.

func hideDesktopIcons() {
        
        let source = """
        on run
            do shell script "chflags hidden ~/Desktop/*"
        end run
        """

        let script = NSAppleScript(source: source)!
        var error: NSDictionary?
        script.executeAndReturnError(&error)
        
        if let error = error {
            print(error)
        }
    }

Also I've made sure that the following keys are set
1

enter image description here

Result:

{
    NSAppleScriptErrorAppName = "Focus";
    NSAppleScriptErrorBriefMessage = "chflags: /Users/deepu/Library/Containers/com.deepu.Focus/Data/Desktop/*: No such file or directory";
    NSAppleScriptErrorMessage = "chflags: /Users/deepu/Library/Containers/com.deepu.Focus/Data/Desktop/*: No such file or directory";
    NSAppleScriptErrorNumber = 1;
    NSAppleScriptErrorRange = "NSRange: {3, 53}";
}

I've read this but doesn't seem to be working at all Hide all desktop icons under Mac OS

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文