IPB

Bienvenue invité ( Connexion | Inscription )

 
Reply to this topicStart new topic
> Applescript - TextEdit [Résolu]
Options
likan
posté 5 Apr 2010, 12:05
Message #1


Nouveau Membre


Groupe : Membres
Messages : 2
Inscrit : 4 Apr 2010
Membre no 152 485



Bonjour à tous,

Je viens ici pour lancer une fusée de détresse !!
J'essaye de faire un truc en applescript depuis 2jours mais je n'y arrive pas..

J'ai pourtant lu de nombreux tutos..

Voici mon problème:

J'aimerais pouvoir via applescript:
1) lancer TextEdit
2) Taper du texte
3) "Enregistrer sous" ce fichier au format .doc !!

Le problème, c'est que j'arrive pas à changer la liste déroulante.. donc il m'enregistre à chaque fois le document en .rtf (premier format de fichier proposé)


Voici mon script :

Citation
tell application "TextEdit"
activate
tell application "System Events"
-- On colle le texte
keystroke "v" using {command down}
delay 1
-- On appel "Enregistrer Sous"
keystroke "s" using {command down}
delay 1
-- On tape le nom qu'on veut donner au fichier
keystroke "documentDeTest"
delay 1

-- Manque la ligne pouvant choisir le format de fichier à enregistrer !!

-- On valide
key code 36
delay 1
-- On quitte l'application
keystroke "q" using {command down}
delay 1
end tell
end tell




En gros, je veux pouvoir aller dans la liste déroulante du format de fichier et sélectionner le format .doc
Apercu : http://nsa14.casimages.com/img/2010/04/05/...14156669788.png




J'espère que vous pourrez m'éclairer.. Je vous en serez très reconnaissant biggrin.gif
Merci.

Ce message a été modifié par likan - 5 Apr 2010, 16:31.
Go to the top of the page
 
+Quote Post
Guest_EricaL**_*
posté 5 Apr 2010, 15:55
Message #2





Guests






Bonjour,

Voici le script sans avoir besoin du GUI Sripting.
Code
set dossier to (path to documents folder)
set t_file to choose file name default name "documentDeTest.doc" default location dossier

tell application "TextEdit" to activate
tell application "System Events" to keystroke "v" using {command down}

tell application "TextEdit"
    save document 1 as "Microsoft Word 97 document" in t_file
    quit
end tell



Sinon avec le GUI Sripting :
Il faut cocher le bouton "Activer l’accès pour les périphériques d’aide" dans les préférences “Accès universel” des “Préférences Système”.

La partie GUI Sripting est à modifier selon la version du système, fonctionne bien sur Mac OS X 10.5.8
Code
tell application "TextEdit" to activate
tell application "System Events" to tell process "TextEdit"
    keystroke "v" using {command down}
    delay 1
    -- On colle le texte    
    -- On appel "Enregistrer Sous"
    keystroke "s" using {command down}
    delay 1
    
    tell sheet 1 of front window --- GUI Scripting
        -- On tape le nom qu'on veut donner au fichier
        keystroke "documentDeTest"
        delay 0.3
        
        tell pop up button 1 of group 1 of group 1
            click
            delay 0.3
            click menu item "Format Word 97 (doc)" of menu 1
        end tell
        
        -- On valide
        key code 36
    end tell
    delay 1
    -- On quitte l'application
    keystroke "q" using {command down}
    delay 1
end tell

Go to the top of the page
 
+Quote Post
likan
posté 5 Apr 2010, 16:34
Message #3


Nouveau Membre


Groupe : Membres
Messages : 2
Inscrit : 4 Apr 2010
Membre no 152 485



Merci beaucoup !!
Les 2 solutions fonctionnent biggrin.gif

Manque juste le point avant "doc" pour le choix du format.
click menu item "Format Word 97 (.doc)" of menu 1


Encore merci, je vais enfin pouvoir avancer. smile.gif
Go to the top of the page
 
+Quote Post
islou
posté 1 Mar 2011, 18:30
Message #4


Nouveau Membre


Groupe : Membres
Messages : 6
Inscrit : 10 Jan 2005
Membre no 30 440



bonjour,

J'ai testé le script avec le GUI Scripting sous léopard 10.5.8 et j'obtiens le message d'erreur suivant

Erreur dans System Events : Il est impossible d’obtenir window 1 of process "TextEdit". Index non valable.

le pop up button semble inaccessible, même en appelant

click pop up button 1 of group 1 of sheet 1 of window 1

j'ai pourtant coché le bouton "Activer l’accès pour les périphériques d’aide" dans les préférences “Accès universel” des “Préférences Système”.

en fait j'aimerais surtout faire fonctionner ce script

TextEdit: Save the current document as HTML If you've opened a named doc it will save it by its name. If it's a new doc, it will be named "Unitled?" with numbers where the ? is. Any formatting in an RTF or Word files is retained in the HTML. Note the two lines where you must remove hyphens if running as a workflow. (Requires UI scripting enabled.)
--Save TextEdit Doc as HTML
--tell application "TextEdit" to activate--remove hypens before "tell" if running as a workflow
tell application "System Events"
tell process "TextEdit"
keystroke "S" using command down
delay 1
click pop up button 1 of group 1 of sheet 1 of window 1
delay 1
key code 125
delay 1
keystroke return
delay 1
keystroke return
end tell
end tell
--end tell --remove hypens before "end" if running as a workflow


merci de votre aide
Go to the top of the page
 
+Quote Post
Guest_EricaL**_*
posté 2 Mar 2011, 15:42
Message #5





Guests






Citation (islou @ 1 Mar 2011, 12:30) *
J'ai testé le script avec le GUI Scripting sous léopard 10.5.8 et j'obtiens le message d'erreur suivant

Erreur dans System Events : Il est impossible d’obtenir window 1 of process "TextEdit". Index non valable.

Premièrement, l'erreur est que le document n'existe pas, parce que TextEdit est déjà ouvert, dans ce cas il n'ouvre pas de nouvelle fenêtre.
Deuxièmement, il faut que les préférences de TextEdit pour les nouveaux documents soient à RTF.

Sinon, on peut le vérifier par script pour éviter ces deux problèmes
Code
tell application "TextEdit"
    if running then make new document -- si TextEdit est déjà ouvert
    activate
end tell
tell application "System Events" to tell process "TextEdit"
    tell menu item "Convertir au format RTF" of menu "Format" of menu bar item "Format" of menu bar 1 to if exists then click -- si la fenetre est au format texte
    keystroke "v" using {command down}
    delay 1
    -- On colle le texte    
    -- On appel "Enregistrer Sous"
    keystroke "s" using {command down}
    delay 1
    
    tell sheet 1 of front window --- GUI Scripting
        -- On tape le nom qu'on veut donner au fichier
        keystroke "documentDeTest"
        delay 0.3
        
        tell pop up button 1 of group 1 of group 1
            click
            delay 0.3
            click menu item "Format Word 97 (doc)" of menu 1
            delay 0.3
        end tell
        -- On valide
        key code 36
    end tell
end tell




Citation (islou @ 1 Mar 2011, 12:30) *
en fait j'aimerais surtout faire fonctionner ce script

TextEdit: Save the current document as HTML If you've opened a named doc it will save it by its name. If it's a new doc, it will be named "Unitled?" with numbers where the ? is. Any formatting in an RTF or Word files is retained in the HTML. Note the two lines where you must remove hyphens if running as a workflow. (Requires UI scripting enabled.)
--Save TextEdit Doc as HTML
--tell application "TextEdit" to activate--remove hypens before "tell" if running as a workflow
tell application "System Events"
tell process "TextEdit"
keystroke "S" using command down
delay 1
click pop up button 1 of group 1 of sheet 1 of window 1
delay 1
key code 125
delay 1
keystroke return
delay 1
keystroke return
end tell
end tell
--end tell --remove hypens before "end" if running as a workflow



Ce script fonctionne, mais seulement si la fenêtre de TextEdit est au format texte (pas au format RTF).

Ce message a été modifié par EricaL** - 2 Mar 2011, 15:43.
Go to the top of the page
 
+Quote Post

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 : 19th April 2024 - 14:57