Menu Selection/Click

Hi!

I’m very new to applescript, but I’ve been working with the automation browser “Fake” for a while and I’d like to do a few things that combine the two. I can’t figure out how to do the following on my brand new macbook pro:

Once Fake has opened, choosing File → Open → Title_of_Workflow
Clicking the “run” button so that Fake will run my workflow.
Select a Buyer’s name on Amazon and copy it into a google doc.

Any ideas how I could do any of these? Any comments would be very helpful!

Thanks, and Happy New Year!

Model: Macbook Pro
AppleScript: 2.4.1
Browser: Chrome/Fake
Operating System: Mac OS X (10.7)

Here are handlers which I use very often.


--=====
(*
my selectMenu("Pages",5, 12)
==== Uses GUIscripting ====
*)
on selectmenu(theApp, mt, mi)
	activate application theApp
	tell application "System Events" to tell application process theApp to tell menu bar 1 to ¬
		tell menu bar item mt to tell menu 1 to click menu item mi
	
end selectmenu

--=====
(*
my selectSubMenu("Pages",6, 4, 26)
==== Uses GUIscripting ====
*)
on selectSubMenu(theApp, mt, mi, ms)
	
	activate application theApp
	tell application "System Events" to tell application process theApp to tell menu bar 1 to ¬
		tell menu bar item mt to tell menu 1 to tell menu item mi to tell menu 1 to click menu item ms
end selectSubMenu

--=====
(*
useful to get the indexs of the triggered item
my select_Menu("Numbers", 5, 16) (* Insert > FileName *)
*)
on select_menu(theApp, mt, mi)
	activate application theApp
	tell application "System Events" to tell process theApp to tell menu bar 1
		get name of menu bar items
		(*{
01 - "Apple", 
02 - "Numbers", 
03 - "Fichier", 
04 - "Édition", 
05 - "Insertion", 
06 - "Tableau", 
07 - "Format", 
08 - "Disposition", 
09 - "Présentation", 
10 - "Fenêtre", 
11 - "Partage", 
12 - "Aide"}
*)
		get name of menu bar item mt
		-- {"Insert"}
		tell menu bar item mt to tell menu 1
			get name of menu items
			(* {
01 - "Feuille", 
02 - missing value, 
03 - "Tableau", 
04 - "Graphique", 
05 - "Figure", 
06 - "Zone de texte", 
07 - "Fonction", 
08 - "Ligne de connexion", 
09 - missing value, 
10 - "Remplissage", 
11 - missing value, 
12 - "Rangs copiés", 
13 - "Colonnes copiées", 
14 - missing value, 
15 - "Date et heure", 
16 - "Nom du fichier", 
17 - "Numéro de page", 
18 - "Nombre de pages", 
19 - missing value, 
20 - "Commentaire", 
21 - "Lien", 
22 - "Saut de colonne", 
23 - missing value, 
24 - "Choisir."}
*)
			get name of menu item mi
			--{"Nom du fichier"}
			click menu item mi
		end tell -- menu bar.
		
	end tell -- System Events
end select_menu

--=====
(*
useful to get the indexs of the triggered item
my select_SubMenu("Numbers", 6, 14, 3) (* Table > Footer rows > 2 *)
*)
on select_SubMenu(theApp, mt, mi, ms)
	
	activate application theApp
	tell application "System Events" to tell process theApp to tell menu bar 1
		get name of menu bar items
		(*{
01 - "Apple", 
02 - "Numbers", 
03 - "Fichier", 
04 - "Édition", 
05 - "Insertion", 
06 - "Tableau", 
07 - "Format", 
08 - "Disposition", 
09 - "Présentation", 
10 - "Fenêtre", 
11 - "Partage", 
12 - "Aide"}
*)
		get name of menu bar item mt
		-- {"Tableau"}
		tell menu bar item mt to tell menu 1
			get name of menu items
			(* {01 - "Insérer un rang au-dessus", 
02 - "Insérer un rang en dessous", 
03 - missing value, 
04 - "Insérer une colonne avant", 
05 - "Insérer une colonne après", 
06 - missing value, 
07 - "Supprimer le rang", 
08 - "Supprimer la colonne", 
09 - missing value, 
10 - "Rangs d'en-tête", 
11 - "Colonnes d'en-tête", 
12 - "Bloquer les rangs d'en-tête", 
13 - "Bloquer les colonnes d'en-tête", 
14 - "Rangs de bas de tableau", 
15 - missing value, 
16 - "Ajuster les rangs au contenu", 
17 - "Ajuster les colonnes au contenu", 
18 - missing value, 
19 - "Afficher tous les rangs", 
20 - "Afficher toutes les colonnes", 
21 - "Activer toutes les catégories", 
22 - missing value, 
23 - "Fusionner les cellules", 
24 - "Diviser en rangs", 
25 - "Diviser en colonnes", 
26 - missing value, 
27 - "Répartir les rangs uniformément", 
28 - "Répartir les colonnes uniformément", 
29 - missing value, 
30 - "Autoriser la sélection de bordure", 
31 - missing value, 
32 - "Afficher le panneau de réorganisation"}
*)
			get name of menu item mi
			--"Rangs de bas de tableau"
			tell menu item mi to tell menu 1
				get name of menu items
				(* {
1 - "0", 
2 - "1", 
3 - "2", 
4 - "3", 
5 - "4", 
6 - "5"}
*)
				get name of menu item ms
				-- "2"
				click menu item ms
			end tell -- menu item.
			
		end tell -- menu bar.
		
	end tell -- System Events
end select_SubMenu

--=====

In fact they are two plus two.

The first ones are the compact ones which are embedded in final scripts.
The last ones are ‘expanded’ which are triggered when the scripts are work in progress.
I may enable some instructions to get the needed parameters.

Jus a sample :

when I want to switch between two Pages documents in scripts using GUIscripting I use :

my selectMenu(“Pages”,9, docName1)
to bring the doc docName1 at front
and
my selectMenu(“Pages”,9, docName2)
to bring the doc docName2 at front.

Yvan KOENIG (VALLAURIS, France) lundi 2 janvier 2012 10:32:14

Very useful Yvan. Embarrassingly noobie question: Where should your definitions like

“on selectmenu()”

be saved for all my scripts to see them?

Two ways :

(1) the one which I use : insert the handlers in the scripts needing them.
It’s the easiest scheme when scripts are written to answer an user question.

(2) store the handlers in a library allowing them to be called by several scripts.

I can’t detail here the library feature.

Look at : AppleScriptLanguageGuide.pdf or study one of the numerous books published upon AppleScript like “AppleScript the definitive book” by Matt Neuburg.

Yvan KOENIG (VALLAURIS, France) mardi 3 janvier 2012 09:14:05