Applescript 使文件夹隐藏和取消隐藏

Applescript 使文件夹隐藏和取消隐藏,applescript,hide,show,directory,Applescript,Hide,Show,Directory,我正试图发出一个命令来隐藏和显示桌面上的文件夹这是我目前在applescript中的代码: on run if "chflags hidden ~/Desktop/*" then do shell script "chflags nohidden ~/Desktop/*" else do shell script "chflags hidden ~/Desktop/*" end if end run 你能找到问题并帮助我吗 谢谢该命令似乎

我正试图发出一个命令来隐藏和显示桌面上的文件夹这是我目前在applescript中的代码:

on run
    if "chflags hidden ~/Desktop/*" then
        do shell script "chflags nohidden ~/Desktop/*"
    else
        do shell script "chflags hidden ~/Desktop/*"
    end if
end run
你能找到问题并帮助我吗
谢谢

该命令似乎按预期工作。我用桌面上的文件夹测试了它,所以

chflags hidden ~/Desktop/testDir/*
chflags nohidden ~/Desktop/testDir/*
他做这项工作

你的if语句不起作用

if "chflags hidden ~/Desktop/*" then
那没用。即使要添加缺少的“do shell脚本”:

这实际上会隐藏所有内容(此时您不需要),并且不会返回任何内容,并生成AppleScript错误

因此,您必须寻找另一种方法来检查隐藏状态

下面是一个代码示例:

tell application "System Events"
    set filePath to file (((path to desktop) as text) & "myReferenceFile.txt")
end tell

set this_info to info for filePath
if visible of this_info is true then
    log "VISIBLE"
else
    log "INVISIBLE"
end if

如果您有一个引用文件,您可以使用该路径来检查它是否隐藏。

您可以使用如下方式切换标志:

property hideFolders : true

if hideFolders then
    do shell script "find ~/Desktop/* -type d -maxdepth 1 -exec chflags hidden {} +"
    set hideFolders to false
else
    do shell script "find ~/Desktop/* -type d -maxdepth 1 -exec chflags nohidden {} +"
    set hideFolders to true
end if
property hideFolders : true

if hideFolders then
    do shell script "find ~/Desktop/* -type d -maxdepth 1 -exec chflags hidden {} +"
    set hideFolders to false
else
    do shell script "find ~/Desktop/* -type d -maxdepth 1 -exec chflags nohidden {} +"
    set hideFolders to true
end if