[AS] Changer le label du fichier (tag de couleur)

Page principale
Supprimer ce message
Répondre à ce message
Auteur: Madert Pascal via Applescript_fr
Date:  
À: Liste AppleScript francophone
CC: Madert Pascal
Sujet: [AS] Changer le label du fichier (tag de couleur)
Bonsoir à tous,

je rajoute un "tell application "Finder" to set label index of (NewFileName) to 2" à mon applescript
Et cela me renvoie une erreur
Il est impossible de régler «class labi» of "Downloads-2021-01-01.xlsx" à 2. (-10006)
pareil si je mets le chemin complet. - chemin2
Il est impossible de régler «class labi» of "Macintosh HD:Users:moi:Downloads:Downloads-2021-01-01.xlsx" à 2. (-10006)
Mais si je place cette commande dans un nouveau script
tell application "Finder" to set label index of (choose file) to 2 (en choisissant le même fichier)
Là ça fonctionne.
Voilà le script : (j'ai mis la commande après le "end tell" de "tell application Finder"

[script]
on open fileNames -- fileNames est une liste d'aliases
    repeat with fileName in fileNames -- boucle censée traiter chacun des aliases de la liste
        tell application "Finder"
            set theFileName to name of fileName
            set theFilePath to fileName as string
            set lextension to name extension of fileName
            set nomcourt to text 1 thru ((length of theFileName) - (1 + (length of lextension))) of theFileName
            set folderPath to folder of fileName as alias
            set folderName to name of folderPath
        end tell
        tell application "Microsoft Excel"
            activate
            open fileName
            set theDate to (value of cell "H2") as date -- retourne une date Applescript conforme aux réglages système
            set theYear to year of theDate as string -- je suppose que l'année est sur quatre chiffres
            if theYear < 100 then set theYear to theYear + 2000 -- suppose que la date relève du XXIème siècle
            set theYear to theYear as string
            set theMonth to text 2 thru 3 of ((100 + (month of theDate as number)) as string) -- on aura toujours deux chiffres
            set theDay to text 2 thru 3 of ((100 + (day of theDate)) as string) -- on aura toujours deux chiffres
            set NouveauTexte to theYear & "-" & theMonth & "-" & theDay
            set NewFileName to folderName & "-" & NouveauTexte & "." & lextension
            set chemin to folderPath as text
            set chemin2 to chemin & NewFileName
            set knt to 0
            repeat
                if my testPresence(chemin2) then
                    set knt to knt + 1
                    set NewFileName to folderName & "-" & NouveauTexte & "-" & knt & "." & lextension
                    set chemin2 to chemin & NewFileName
                else
                    exit repeat
                end if
            end repeat
            tell application "Finder" to set name of fileName to NewFileName
            tell application "Microsoft Excel" to close window 1
        end tell
        tell application "Finder" to set label index of (NewFileName) to 2
    end repeat -- limite de la boucle
end open


on testPresence(p2f)
    tell application "Finder"
        return (exists file p2f)
    end tell
end testPresence
[script]
_______________________________________________
Applescript_fr mailing list
Applescript_fr@???
http://listes.patpro.net/mailman/listinfo/applescript_fr