令 Finder 顯示 / 不顯示 隱藏檔的 applescript

本區專門提供 Mac OS X 使用者交換使用心得

版主: ross_ttbryanchangdigdogchester

回覆文章
內容
發表人
留言五百如一日
文章: 610
註冊時間: 12/25/2001 1:01 am

令 Finder 顯示 / 不顯示 隱藏檔的 applescript

#1 文章 »

Finder 預設是不顯示隱藏檔,如欲、可改動 Finder 的 plist [1];在 Script Editor 試試這:

代碼: 選擇全部

try
	if word -1 of (do shell script "defaults read com.apple.finder | grep AppleShowAllFiles") = "true" then
		do shell script "defaults write com.apple.finder AppleShowAllFiles false"
	else
		do shell script "defaults write com.apple.finder AppleShowAllFiles true"
	end if
on error
	do shell script "defaults write com.apple.finder AppleShowAllFiles true"
end try

tell application "Finder" to quit
delay 3
tell application "Finder" to activate

上述指令 toggle Finder 顯示 / 不顯示隱藏檔。

略述:如 ~/Library/Preferences/com.apple.finder.plist 內未有 AppleShowAllFiles 此 key 或 其值為 false;則設為 true。反之,設定 AppleShowAllFiles 為 false。

用 defaults write 改動 plist,Finder 需再啟動才見效。



[1] 參看:File-System Structure and Visibility
頭像
the real unknown
冰果室打手
文章: 2610
註冊時間: 04/26/2001 1:01 am
來自: GMT-5
聯繫:

#2 文章 the real unknown »

這只能控制Finder顯不顯示所有隱藏檔,不能真的改屬性。所以其他軟體還是看不到。也不能選擇性的設定。而且我不敢在使用者背後改不是我的程式的設定。

我有找到可以用 do shell script "SetFile..." 可是使用者要裝 developer tools。所以也不行。目前先將就用 do shell script "cp..." 了。還好要處理檔案都不大。

Thanks.
Eat well. Exercise. And die anyway.
留言五百如一日
文章: 610
註冊時間: 12/25/2001 1:01 am

#3 文章 »

要個別改動檔案的 visibility 屬性, /Developer/Tools/SetFile 是正途。

隱藏檔分三類:visibility 屬性為 false、名稱的第一個字元為 "." 及 /.hidden 所定義的檔案或資料夾。

visibility 屬性是 OS9 或前所遺留;Unix 的東西通常用 dot file 型式來隱藏 及 visibility 是 true。

山不轉人轉,試試在 Finder 按 shift command G,輸入 unix 路徑,則可在 Finder 視窗檢視隱藏檔。
其他軟體還是看不到
問題不大,只需 Finder 看到並轉介。例,用 Script Editor 執行

代碼: 選擇全部

tell application "Finder" to open (choose file)
如在 choose file 選了 "/.hidden",則 TextEdit.app 會啟動並開啟此文件。

如在 choose file 選了 "/private/tmp/printing.510/Print job.pdf",則 Preview.app 會啟動並開啟此 PDF。


或,指定某應用程式開啟

代碼: 選擇全部

tell application "QuickTime Player" to open (choose file)
如在 choose file 選了 "/private/tmp/501/Temporary Items/DSCN1234.JPG",則 QuickTime Player.app 會啟動並開啟此 JPG。


又,已知 unix 路徑,真接用 Finder 複製之

代碼: 選擇全部

set uPath to "/sbin" as POSIX file as alias
tell application "Finder" to duplicate uPath to desktop with replacing
此例中,Finder 複製了 "/sbin" 到桌面。
頭像
the real unknown
冰果室打手
文章: 2610
註冊時間: 04/26/2001 1:01 am
來自: GMT-5
聯繫:

#4 文章 the real unknown »

That is all good. But the problem is, the purpose of this "thingy" is to allow user to see and work with the invisible files any way they want. I have no idea what they want to do with the files. So the only way is to change the Finder attributes.

Those files are from some private system that writes the file with leading period in the names. And when OS X sees the files on the server, it automatically set it to invisible. So not only I have to rename it, I also have to reset the Finder attributes. :(

If I enable Finder to see all invisible files, user is going to be overwhelmed by all the nonsense filenames in OS X. So...
Eat well. Exercise. And die anyway.
留言五百如一日
文章: 610
註冊時間: 12/25/2001 1:01 am

#5 文章 »

Those files are from some private system that writes the file with leading period in the names. And when OS X sees the files on the server, it automatically set it to invisible. So not only I have to rename it, I also have to reset the Finder attributes.
AFAIK,絕大多數 dot file 的 visibility 是 true。OS 或 Finder 沒有自行改動其 Finder attributes。只需改名,檔案會顯現;毋用改 invisible bit。同理,dot file 只改動 invisible bit,仍然是隱藏檔。


多難局 :?

- 棄 Finder,用 Terminal.app :wink:

- 採原建議,說服用者 奇異檔名 多見不怪 8)

- 改所述 private system,停產 dot file :evil:
頭像
janusng
嗜冰客
文章: 1048
註冊時間: 04/30/2001 1:01 am
來自: Metropolis Asylum
聯繫:

#6 文章 janusng »

還可以用PathFinder!

我常常用。 :P
回覆文章