Script modifié pour corriger les permissions sans intervention manuelle autre que saisir une fois le mot de passe.
-- début du script
----------------------------------------------------------------
use AppleScript version "2.5"
use framework "Foundation"
--use script "Metadata Lib" version "2.0.0"
use scripting additions
----------------------------------------------------------------
on listFolder:targetDir
set posixPath to POSIX path of targetDir
set off7 to (count posixPath) + 1
set theFolderURL to current application's NSURL's fileURLWithPath:posixPath
set NSDirectoryEnumerationSkipsHiddenFiles to a reference to 4
set NSFileManager to a reference to current application's NSFileManager's defaultManager()
-- set {theURLs, theError} to NSFileManager's defaultManager()'s contentsOfDirectoryAtURL:targetDir includingPropertiesForKeys:{} options:(NSDirectoryEnumerationSkipsHiddenFiles) |error|:(reference)
set typeIdentifierKey to current application's NSURLTypeIdentifierKey
set keysToRequest to current application's NSArray's arrayWithObject:(typeIdentifierKey)
set theURLs to (NSFileManager's enumeratorAtURL:theFolderURL includingPropertiesForKeys:keysToRequest options:6 errorHandler:(missing value))'s allObjects()
if theURLs is equal to missing value then error (theError's localizedDescription() as text)
--set theURLs to theURLs's allObjects()
set sortDesc to current application's NSSortDescriptor's sortDescriptorWithKey:"path" ascending:true selector:"localizedStandardCompare:" -- Finder-style sorting
set theURLs to theURLs's sortedArrayUsingDescriptors:{sortDesc}
set theDescriptors to {}
repeat with aURL in theURLs
set itsPath to (aURL's valueForKey:"path") as text
set {theResult, theValue, theError} to (aURL's getResourceValue:(reference) forKey:(current application's NSURLIsDirectoryKey) |error|:(reference))
if theResult as boolean is false then error (theError's |localizedDescription|() as text) number (theError's code() as integer)
set stripped to text off7 thru -1 of itsPath
if theValue as boolean then
-- c'est un dossier, on s'en fout
else
set itsAttributes2 to ""
try
set itsAttributes to do shell script "stat -F " & quoted form of itsPath
set itsAttributes to text 1 thru 12 of itsAttributes
on error
set itsAttributes to "????"
end try
if itsAttributes is not "-rw-r--r--" then # Adapter le test à ce que vous voulez comme permissions
-- "-rwxr-xr-x" pour chmod 755
-- "-rwxrwxrwx" pour chmod 777
do shell script "chmod 644 " & quoted form of itsPath with administrator privileges # Adapter à ce que vous voulez comme permissions. Le mot de passe ne sera demandé qu'une fois
set itsAttributes2 to do shell script "stat -F " & quoted form of itsPath
set itsAttributes2 to text 1 thru 12 of itsAttributes2
end if
-- set end of theDescriptors to itsPath & tab & itsAttributes
if itsAttributes2 is not "" then
set end of theDescriptors to stripped & tab & itsAttributes & tab & itsAttributes2
else
set end of theDescriptors to stripped & tab & itsAttributes
end if
end if
end repeat
return theDescriptors
end listFolder:
-- set targetDir to (path to desktop as text) & "dossier test:" as alias -- utilisé pour tester
set targetDir to (path to pictures folder as text) & "Photos Library.photoslibrary:Masters:" as alias
set theDescriptors to my listFolder:targetDir
set dateStamp to my dateTimeStamp()
set p2d to path to desktop as text
my writeto(p2d & "Clichés " & dateStamp & ".txt", my recolle(theDescriptors, linefeed), «class utf8», false)
#=====
on recolle(l, d)
local oTIDs, t
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end recolle
#=====
(*
Handler borrowed to Regulus6633 - http://macscripter.net/viewtopic.php?id=36861
*)
on writeto(targetFile, theData, dataType, apendData)
-- targetFile is the path to the file you want to write
-- theData is the data you want in the file.
-- dataType is the data type of theData and it can be text, list, record etc.
-- apendData is true to append theData to the end of the current contents of the file or false to overwrite it
try
set targetFile to targetFile as «class furl»
set openFile to open for access targetFile with write permission
if not apendData then set eof of openFile to 0
write theData to openFile starting at eof as dataType
close access openFile
return true
on error
try
close access targetFile
end try
return false
end try
end writeto
#=====
on dateTimeStamp()
tell (current date) to return (((its year) * 10000 + (its month) * 100 + (its day)) as text)
end dateTimeStamp
#=====
-- fin du script
Le fichier texte créé vous permettra d'identifier les fichiers dont les permissions ont été modifiées en affichant leur état initial et l'état modifié.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 2 juillet 2019 09:20:20
_______________________________________________
Applescript_fr mailing list
Applescript_fr@???
http://listes.patpro.net/mailman/listinfo/applescript_fr