IPB

Bienvenue invité ( Connexion | Inscription )

> Comment changer l'icone d'un répertoire en applescript ?
Options
bruce_luc
posté 26 Oct 2006, 18:07
Message #1


Nouveau Membre


Groupe : Membres
Messages : 2
Inscrit : 6 Sep 2005
Membre no 45 306



Bonjour,

Je voudrais écrire un script qui fixe l'icone d'un répertoire à partir d'un fichier png.
Je veux automatiser un maximum d'étapes. Je n'y arrive pas... mais bon, je suis débutant en applescript.
J'ai réussi à faire :

CODE

tell application "Finder"
    set icon_image_file to file "mon_icon.png" of folder "Users:Users:luc:Desktop"
    set testdir to folder "test" of folder "Users:Users:luc:Desktop"
    
    -- save icon_image with itself as icon
    set icon_image_file_string to icon_image_file as string
    tell application "Image Events"
        launch
        set icon_image to open file icon_image_file_string
        save icon_image with icon
        close icon_image
    end tell
    -- ici on a bien le fichier png icon_image_file qui a changé d'icone

    -- NE FONCTIONNE PAS
    set icon of testdir to icon of icon_image_file
    
end tell
end run


Comme vous pouvez le voir, je n'arrive pas copier l'icone de icon_image_file sur un répertoire (sur un fichier non plus d'ailleurs).
J'ai cherché partout le web, et je n'ai rien trouvé si ce n'est des solutions qui ne fonctionnent pas.

Avez-vous des idées ?

Luc.

Ce message a été modifié par bruce_luc - 26 Oct 2006, 18:44.
Go to the top of the page
 
+Quote Post
 
Start new topic
Réponse(s)
bruce_luc
posté 28 Oct 2006, 11:34
Message #2


Nouveau Membre


Groupe : Membres
Messages : 2
Inscrit : 6 Sep 2005
Membre no 45 306



Salut,

Voici la solution :

CODE

on run
    set icon_image_file to file "Users:Users:luc:Desktop:mon_icon.png" as alias
    set testdir to file "Users:Users:luc:Desktop:test" as alias
    
    my saveImageWithItselfAsIcon(icon_image_file)
    my copyIconOfTo(icon_image_file, testdir)
end run

on saveImageWithItselfAsIcon(icon_image_file)
    -- save icon_image_file with itself as icon    
    set icon_image_file_string to icon_image_file as string
    tell application "Image Events"
        launch
        set icon_image to open file icon_image_file_string
        save icon_image with icon
        close icon_image
    end tell
end saveImageWithItselfAsIcon

on copyIconOfTo(aFileOrFolderWithIcon, aFileOrFolder)
    tell application "Finder" to set f to aFileOrFolderWithIcon as alias
    -- grab the file's icon
    my CopyOrPaste(f, "c")
    -- now the icon is in the clipboard
    tell application "Finder" to set c to aFileOrFolder as alias
    my CopyOrPaste(result, "v")
end copyIconOfTo

on CopyOrPaste(i, cv)
    tell application "Finder"
        activate
        open information window of i
    end tell
    tell application "System Events" to tell process "Finder" to tell window 1
        keystroke tab -- select icon button
        keystroke (cv & "w") using command down (* (copy or paste) + close window *)
    end tell -- window 1 then process Finder then System Events
end CopyOrPaste



Merci à Yvan sur MacScripter...

Luc.

Ce message a été modifié par bruce_luc - 29 Oct 2006, 01:01.
Go to the top of the page
 
+Quote Post

Les messages de ce sujet


Reply to this topicStart new topic
1 utilisateur(s) sur ce sujet (1 invité(s) et 0 utilisateur(s) anonyme(s))
0 membre(s) :

 



Nous sommes le : 11th November 2025 - 01:14