2011-01-21 120 views
1

我公司的員工有時會暫時擱置一個文件,因爲某些原因,他們沒有讀取或寫入權限。一個示例是從客戶端FTP服務器下載文件。當您沒有讀取權限時,使用Applescript更改文件權限

我期待創造一個東西很簡單,AppleScript的液滴,將更改文件的權限下降就可以了:

on open filelist 
repeat with i in filelist 
    do shell script "chmod -R +wr " & quoted form of POSIX path of i with administrator privileges 
end repeat 
end open 

的問題是,由於用戶不具有讀取的權限,在on open filelist線上液滴立即失效。在on open塊之間

卸下一切:

on open filelist 
end open 

仍然導致腳本失敗。如果失敗,我的意思是它會產生文件權限錯誤。

在此先感謝。

+0

你需要使用AppleScript的,或者可能你只需創建一個包含搭配chmod -R + RW $ 1 shell腳本,並有用戶運行? (另外,如果你需要-R,你可能需要+ rwX,因爲目錄需要執行位。) – 2011-01-21 22:32:55

回答

1

問題可能是您正在嘗試處理用戶無法讀取的文件 - 這將導致Droplet無法正常工作,因爲它取決於能夠讀取! 您需要使用文件選擇器編寫適當的應用程序。這裏的問題是,您可以選擇多個文件,但只能選擇文件或文件夾。 反正從來就寫在過去類似的東西,可以隨意使用:

set myUsername to (short user name of (system info)) 
set myPassword to "" 

set fileOrFolder to button returned of (display dialog "Would you like to change permissions on files of folders?" buttons {"Cancel", "Files", "Folders"} default button "Cancel") 

if fileOrFolder is "Files" then 
set theSelection to choose file with multiple selections allowed without invisibles 

repeat with oneFile in theSelection 

do shell script "sudo chmod -R u+rwX,go+rX " & quoted form of POSIX path of oneFile password myPassword with administrator privileges 
do shell script "sudo chown -R " & myUsername & ":staff " & quoted form of POSIX path of oneFile password myPassword with administrator privileges 

end repeat 
else if fileOrFolder is "Folders" then 
set theSelection to choose folder with multiple selections allowed without invisibles 

repeat with oneFile in theSelection 

do shell script "sudo chmod -R u+rwX,go+rX " & quoted form of POSIX path of oneFile password myPassword with administrator privileges 
do shell script "sudo chown -R " & myUsername & ":staff " & quoted form of POSIX path of oneFile password myPassword with administrator privileges 

end repeat 
else 
display dialog "Error" 
end if 
+0

謝謝Asmus。雖然這不是一滴水,但AppleScript似乎不可能,但它仍然會爲非技術人員修復權限提供一種簡便的方法。 – kfriend 2011-01-24 04:16:23