2013-12-09 77 views
5

我剛剛得到了我的視網膜MBP,我真的是新的Mac OS X(使用PC之前)。我注意到Mac沒有GUI來顯示/隱藏像Windows這樣的隱藏文件。我研究過,看到這個網站Show Hidden Files on your Mac。是的,它的工作原理。如何使腳本在Mac OS X中顯示/隱藏隱藏文件?

顯示隱藏文件: (使用終端) 默認寫com.apple.finder AppleShowAllFiles TRUE killall Finder

要隱藏隱藏文件: ​​

什麼,我想要做的就是讓一個可執行腳本,將執行上述命令時,我雙擊它,以便我不必在終端中鍵入命令,以便我顯示/隱藏隱藏的文件。我看到了Applescript,但我並不是很熟悉它。我不知道執行我想要的命令。但我讀過一些。

有人可以幫我做一個可執行腳本,將顯示/隱藏我的Mac中的隱藏文件?

回答

0

我看到一個鏈接,它提供了顯示/隱藏隱藏文件的選項。

http://appducate.com/2013/01/how-to-show-hidden-files-folders-on-your-mac/

我用的Automator腳本,你可以從我給的鏈接下載。

爲了讓我更有效地顯示/隱藏隱藏文件,我將腳本保存爲使用Automator的應用程序。

然後創建了「顯示隱藏隱藏文件」應用程序的快捷鍵,我用在這裏發現的步驟創建:

https://superuser.com/questions/245711/starting-application-with-custom-keyboard-shortcut

,現在我只需要按下鍵盤快捷鍵,如果我想要顯示或隱藏隱藏的文件。我可以在任何應用程序中這樣做。 :)

順便說一句,謝謝大家的答案。這只是另一種有效顯示/隱藏隱藏文件的方式。

9
display dialog "Show all files" buttons {"TRUE", "FALSE"} 
set result to button returned of result 
if result is equal to "TRUE" then 
    do shell script "defaults write com.apple.finder AppleShowAllFiles -boolean true" 
else 
    do shell script "defaults delete com.apple.finder AppleShowAllFiles" 
end if 
do shell script "killall Finder" 

enter image description here

使用AppleScript的編輯並保存爲應用。

enter image description here

+0

感謝您的回答。順便說一句,爲什麼命令成爲刪除?它會輸出相同的結果嗎? 「默認**刪除** com.apple.finder AppleShowAllFiles」 – daremigio

+0

默認寫入com.apple。取景器AppleShowAllFiles -boolean false不工作10.9 osx –

+0

噢好吧。所以這就是爲什麼。 – daremigio

0

這裏有一個腳本來切換所有隱藏文件的可見性。

set myShell to "defaults read com.apple.Finder AppleShowAllFiles" 
set myVisible to (do shell script myShell) 
if myVisible = "0" then 
    set myShell to "defaults write com.apple.Finder AppleShowAllFiles 1" 
else 
    set myShell to "defaults write com.apple.Finder AppleShowAllFiles 0" 
end if 
set myResult to (do shell script myShell) 
tell application "Finder" 
    quit 
    delay 2 
end tell 
activate application "Finder" 
return myVisible 

我不記得爲什麼我按照自己的方式寫了它,爲什麼我在最後添加了返回命令。我知道它可以在10.6.8以後的所有版本的OSX上運行。 Parag Bafna與其他答案的不同之處在於,您並未被問到是否顯示或隱藏文件。如果這些文件被隱藏,則會顯示它們,如果它們可見,則它們將被隱藏。

+0

@DigiMonk我真的很驚訝,它很重要。文章沒有解釋爲什麼。也許這隻有在將硬盤格式化爲「Mac OS Extended(區分大小寫)」時才重要。 – Mark

+0

@DigiMonk是什麼錯誤?如果你告訴我這個錯誤,我會調整腳本。 – Mark

+0

@DigiMonk我在其他版本的OSX中嘗試了這一點,即使shell返回錯誤,它也不是問題。你有沒有在OSX 10.9中試過這個?你能在這裏粘貼錯誤信息的文字嗎?它在第一次運行腳本時根本不會執行任何操作。如果你在腳本中切換0和1,它就會起作用。 – Mark

3

你也可以使用的Automator像這樣創建一個服務:

do shell script "[[ $(defaults read com.apple.finder AppleShowAllFiles) = 1 ]] && b=false || b=true 
defaults write com.apple.finder AppleShowAllFiles -bool $b" 
tell application "Finder" 
    quit 
    delay 0.2 -- without this delay there was a "connection is invalid" error 
    reopen -- open a new default window 
    activate -- make Finder frontmost 
end tell 

,您可以給服務從鍵盤預置面板的快捷鍵。

0

要顯示或隱藏的Mac OSX ElCaptain文件,這是使用別名一個簡單的腳本。創建一個別名,並將其綁定在function.So:

#!/bin/bash 

#create an alias with function 

a="s" 
b="h" 

function showHideFiles(){ 
if [[ "$1" = "$a" ]];  #show hidden files 
then 
    defaults write com.apple.finder AppleShowAllFiles true; killall Finder 
elif [[ "$1" = "$b" ]];  #hide hidden files 
then  
    defaults write com.apple.finder AppleShowAllFiles false; killall Finder 
fi 
} 

alias files=showHideFiles 
1

基於@ user495470的answer ...

在MacOS上塞拉(可能)之前,你可以扔在運行蘋果本腳本框在automator代替:

do shell script "[[ $(defaults read com.apple.finder AppleShowAllFiles) = ON ]] && b=OFF || b=ON 
defaults write com.apple.finder AppleShowAllFiles $b 
killall Finder" 

換行符問題(否則我會剛纔評論過上面的內容)。

killall Finder取代整個tell塊,因爲它會在準備就緒時重新啓動。

1

我更喜歡堅持使用shell腳本。在@ user495470的答案再次提出,切換隱藏文件,並重新啓動取景器的腳本是:

[[ $(defaults read com.apple.finder AppleShowAllFiles) = ON ]] && b=OFF || b=ON 
defaults write com.apple.finder AppleShowAllFiles $b 
killall Finder 

您可以將所有腳本存儲在~/bin。如果您保存上面的代碼到〜/斌/ toggle_files.command,這使你的腳本的可執行文件:

chmod +x ~/bin/togglefiles.command 

該腳本現在是「點擊」。我的媽媽更喜歡點擊她的shell腳本,而她將它們存儲在~/Documents/Scripts。我想這是一個品味問題。爲了從終端喚起你的腳本(我喜歡這樣做),你應該在你的配置文件中創建一個別名。我使用bash(我認爲它是OS X中的默認設置),你的bash配置文件將在~/.bash_profile。如果添加

alias togglefiles="~/bin/togglefiles.command" 

~/.bash_profile,所有的終端會話將把命令togglefiles作爲定位在bin -directory你的shell腳本調用。

7

你不需要腳本了。打開取景器,按 + ⇧Shift + 它會顯示/隱藏你的文件。