Boolean of GUI Scripting, question.

At last I got this working, but I feel the code maybe are not correct in syntax.

This is GUI Script in Numbers to switch ON/OFF Gridlines of a Table sheet.

Numbers return a value of 0 or 1, it’s not possible to to set value, so the only option I have is click.

I had a question from my first post, but I end up to this code, that work.

EDIT: This code remove the ‘error’ if wrong radio group…

property gridlinesColumn : false
property gridlinesRow : false

gridlinesTableSwitch(gridlinesColumn, gridlinesRow)

on gridlinesTableSwitch(_boolValueColumn, _boolValueRow)
	tell application "System Events" to tell application process "Numbers"
		set frontmost to true
		
		-- Table
		tell window 1 to tell radio group 1
			------------------------------------
			-- Set the radio button
			set radioButtonList to {"Table", "Cell", "Text", "Arrage"}
			click radio button (my listPosition("Table", radioButtonList))
		end tell
		
		-- Gridlines
		tell window 1 to tell scroll area 3 to tell group 2
			-- Get the status.
			set statusValueColumn to its value of checkbox 1
			set statusValueRow to its value of checkbox 2
			
			if statusValueColumn is (my boolValue(_boolValueColumn)) then
				click checkbox 1
			end if
			
			if statusValueRow is (my boolValue(_boolValueRow)) then
				click checkbox 2
			end if
		end tell
	end tell
end gridlinesTableSwitch

on boolValue(_status)
	if _status = true then
		return 0
	else
		return 1
	end if
end boolValue

on listPosition(_item, _list)
	repeat with i from 1 to the count of _list
		if item i of _list is _item then return i
	end repeat
	return 0
end listPosition

Maybe this code will be helpful.

property gridlinesColumn : 0 -- was false
property gridlinesRow : 1 -- was true

tell application "Numbers"
	set table_loc to localized string "Table" from table "TSTables"
end tell

tell application "System Events" to tell application process "Numbers"
	set frontmost to true
	-- must reveal the Format Inspector
	set {mt, mi, ms} to {10, 4, 1} -- 4 is index of menu item Inspector, 1 is index of submenu item Format
	--tell menu bar 1 to tell menu bar item mt to tell menu 1 to tell menu item mi to tell menu 1 to get name of menu item ms--> Formater
	tell menu bar 1 to tell menu bar item mt to tell menu 1 to tell menu item mi to tell menu 1 to tell menu item ms
		-- its attributes
		-- value of its attributes
		-- set checked to value of its attribute "AXMenuItemMarkChar" -- missing value or "✓"
		if value of its attribute "AXMenuItemMarkChar" is missing value then click it
	end tell --> Formater
	-- Now the Format Inspector is available
	tell window 1
		-- must check that the Table pane is active
		-- class of UI elements --> {scroll area, button, scroll area, button, button, scroll area, button, button, radio group, scroll area, button, button, button, menu button, toolbar, tab, static text, static text}
		tell radio group 1
			-- name of radio buttons --> {"Tableau", "Cellule", "Texte", "Disposition"}
			click radio button table_loc -- Tableau -- activate the Table pane
		end tell
		(*
		tell scroll area 1
			class of UI elements --> {scroll bar, scroll bar}
		end tell
		tell scroll area 2
			class of UI elements --> {static text}
		end tell
		try
			tell scroll area 3
				class of UI elements --> {static text, static text}
			end tell
		end try
		try
			tell scroll area 4
				class of UI elements --> {static text, pop up button, pop up button, pop up button, checkbox, static text, text field, incrementor, static text, text field, incrementor, static text, group, static text, pop up button, color well, text field, incrementor, checkbox, static text, group, group, checkbox, color well, static text, text field, incrementor, button, static text, text field, incrementor, button, static text, scroll bar}
			end tell
		end try
		*)
		repeat with i from 1 to count scroll areas
			if exists group 2 of scroll area i then exit repeat -- On my system it's with i = 4
		end repeat
		tell scroll area i to tell group 2
			-- class of UI elements --> {checkbox, checkbox}
			-- get help of checkbox 1 --> "Affichez ou masquez le quadrillage horizontal des colonnes du corps."
			-- get help of checkbox 2 --> "Affichez ou masquez le quadrillage vertical des rangs du corps."
			
			set {statusValueColumn, statusValueRow} to value of checkboxes
			(*
			if gridlinesColumn = 1 then
				set gridColumn to 0
			else
				set gridColumn to 1
			end if
			if gridlinesRow = 1 then
				set gridRow to 0
			else
				set gridRow to 1
			end if
			*)
			set gridColumn to item (gridlinesColumn + 1) of {1, 0}
			set gridRow to item (gridlinesRow + 1) of {1, 0}
			if statusValueColumn is gridColumn then click checkbox 1
			if statusValueRow is gridRow then click checkbox 2
		end tell
	end tell
end tell

If you are satisfied with it, you may delete the commented out instructions which were needed only to write the code.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 16 mars 2020 23:02:47

Thanks Yvan.

The approach you have taken does that involve the code will run on different localized strings?

Also I need the property to be true or false, because the value 0 or 1 could also be integer.
It would make more sense to me to separate boolean value from integer.

Interesting, your code, tell me your working flow how you do it ??

Regards.

It seems that I misunderstood what you asked for.
As far as I know, at least in iWork components, the value of a checkbox is always the integer 0 or 1 so I don’t see the need to introduce booleans in the scheme even if I think that using the values false or true would have been more logical (testing a boolean is faster than testing the value of an integer).

As is the script is supposed to work with every localization setting.
I wished to grab the localized spelling for

“Importer” – menu item 4
“Formater” – submenu item 1

Such strings are defined in available resources but not in files dedicated to Numbers.
So I am not sure that the way they are localized match the way they are in Numbers.

For a late one
“Présentation” – menu 10 (View in English)
resources are available but I am annoyed.
I know that I added some resource files to my copy of iWork apps so I’m not sure that what I see is what would be returned on other machines.
This code would return the correct values under Mojave and Catalina but I’m not sure for High Sierra running in French.

tell application "Numbers"
	set view_loc to localized string "View" from table "TSApplication"
	set view295_loc to localized string "295.title" from table "MainMenu"
	set view296_loc to localized string "296.title" from table "MainMenu"
end tell
{view_loc, view295_loc, view296_loc} --> {"Présentation", "Présentation", "Présentation"}

I’m sure that I added the French table “MainMenu” but I don’t remember if I did the same for “TSApplication”.
If I remember well, the numerical indexes used to point these components of a menu are unchanged since several years so I feel that we may use them “safely”.

When I face a problem requiring GUI scripting, one of my most used tool is this set of handlers :

my select_Menu("Numbers", 5, 16)
my select_SubMenu("Numbers", 10, 4, 1)

#=====
(*
useful to get the indexs of the triggered item
my select_Menu("Numbers", 5, 16) (* Insert > FileName *)
*)
on select_Menu(theApp, mt, mi)
	tell application id "com.apple.systemevents" to tell process theApp
		set frontmost to true
		tell menu bar 1
			get name of menu bar items --> {"Apple", "Numbers", "Fichier", "Édition", "Insérer", "Tableau", "Organiser", "Format", "Disposition", "Présentation", "Partager", "Fenêtre", "Aide"}
			get name of menu bar item mt --> "Insérer" -- to check that I use the correct index
			tell menu bar item mt to tell menu 1
				get name of menu items --> {"Feuille", missing value, "Saut de ligne", "Saut de colonne", missing value, "Numéro de page", "Nombre de pages", "Date et heure", missing value, "Tableau", "Graphique", "Zone de texte", "Figure", "Ligne", "Surligner", "Commenter", "Galerie d’images", "Enregistrer l’audio", missing value, "Rangs copiés", "Colonnes copiées", missing value, "Formule", "Équation…", missing value, "Choisir…"}
				get name of menu item mi --> "Commenter" -- to check that I use the correct index
				-- click menu item mi -- disabled when the code is used to scan an item
			end tell -- menu bar…
		end tell
	end tell -- System Events
end select_Menu

#=====
(*
useful to get the indexs of the triggered item
my select_SubMenu("Numbers", 10, 4, 3) (* Table > Footer rows > 2 *)
*)
on select_SubMenu(theApp, mt, mi, ms)
	tell application id "com.apple.systemevents" to tell process theApp
		set frontmost to true
		tell menu bar 1
			get name of menu bar items --> {"Apple", "Numbers", "Fichier", "Édition", "Insérer", "Tableau", "Organiser", "Format", "Disposition", "Présentation", "Partager", "Fenêtre", "Aide"}
			get name of menu bar item mt -- {"Tableau"} -- to check that I use the correct index
			tell menu bar item mt to tell menu 1
				get name of menu items --> {"Masquer la barre d’onglets", "Afficher tous les onglets", missing value, "Inspecteur", missing value, "Afficher les règles", "Guides", missing value, "Commentaires", missing value, "Masquer les activités de la collaboration", missing value, "Afficher les outils de disposition", "Afficher les couleurs", "Afficher les outils d’ajustement de l’image", "Afficher le navigateur multimédia", missing value, "Agrandir/réduire", missing value, "Afficher les avertissements", missing value, "Activer le mode plein écran", missing value, "Masquer la barre d’outils", "Personnaliser la barre d’outils…"}
				get name of menu item mi --> "Inspecteur" -- to check that I use the correct index
				tell menu item mi to tell menu 1
					get name of menu items --> {"Formater", "Organiser", missing value, "Afficher l’onglet suivant de l’inspecteur", "Afficher l’onglet précédent de l’inspecteur", missing value, "Masquer l’inspecteur"}
					get name of menu item ms --> "Formater" -- to check that I use the correct index
					-- click menu item ms -- disabled when the code is used to scan an item
				end tell -- menu item…
			end tell -- menu bar…
		end tell
	end tell -- System Events
end select_SubMenu

#=====

which I use to scan the menus which must be triggered.
We can’t rely upon what we see on screen to know which is the true index of a menu item because some items may have several wording. A common case is the duo “Show something” - “Hide something”. Both appear at the same position but may have different indexes.

For other features, I scan the GUI hierarchy as you may see in the scripts which I posted here and there.

class of UI elements give the list of elements available at a given level.
In this list we see items whose properties are directly available: buttons, checkboxes …
and items containing other UI elements like sheet, table, scroll area…
With such items, we must issue a tell command then ask for the embedded UI elements.
You have some examples in the script passed in this thread (and of course in quite all my GUIScripting proposals).

I used an Apple’s tool : Accessibility Inspector.app but I never understood how to use its ‘modern’ version (5.0 or higher which is in the XCode package installed on my system has no help file available). When I am puzzled, I return to a copy of the old version 3.0 which, happily is 64bits aware.

I know that these is a third party tool available : UIBrowser (https://pfiddlesoft.com/uibrowser/) but I don’t want to pay $55.50 for a tool used to help others for free and, when I tested it I was not convinced of its interest.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 17 mars 2020 14:50:52

Thanks Yvan, for your dedication to write a beautiful message.
I learn something new every time you write back to me.

I do not mind to do the hard way to get the information I seek. Many times I learn something
I didn’t for see and extra bonus of the path I choose. My mind is like that and many times the
greatest ideas is not the first ones no matter what the result is.

There is always ways to improve discover and innovate.

I also use class of UI elements but I also discover that attribute “AXFocusedUIElement” could be useful to search for right UI elements.

name, static text, description, accessibility description and help can give more info.

I have never used attribute “AXMenuItemMarkChar” but now I interesting to know.
I saw it on your preview posts.

I do ask for properties of attributes but many times I’m not so sure what all does.

I hope you are fine, be careful ‘Cornavirus’ have take the Europe, France have close the boarder.
Regards,

I have a idea I like to do in Numbers. It involve to make handlers to build a working script.
This script will include random positions of shape object on A4 size frame. There I will create
amount of shape objects with random positions.This object will have picture frame and other properties.

Extra would be set file list of pictures and pick random items for the picture frame.

The end result will be A4 format with amount of picture frames.

Some properties I have find in the dictionary of Numbers but it’s limited.

So thats why I need to build handlers for specific functions in Numbers. So I could have a good
structor and also be able to use the code in other projects.

I have never done random position before with AppleScript.
I guess I need to have min and max value (pt) and minus the border of A4.

That is my idea :slight_smile:

Regards.

Grabbing attributes is a bit cumbersome.
get attributes of menu item 1 give the list of attributes
get value of attributes of menu item 1 give the list of the value of each attribute

linking value to kind of attribute is a bit boring but while I wrote this words I thought that I am an ass.
It would be more efficient to stop using get attributes and ask for name of attributes of menu item i with this kind of code:

tell menu bar 1 to tell menu bar item mt to tell menu 1 to tell menu item mi to tell menu 1 to tell menu item ms
		set attributesDatas to {}
		repeat with i from 1 to count its attributes
			set end of attributesDatas to {name of attribute i, value of attribute i}
		end repeat
		return attributesDatas
		-- set checked to value of its attribute "AXMenuItemMarkChar" -- missing value or "✓"
		--if value of its attribute "AXMenuItemMarkChar" is missing value then click it
		
	end tell --> Formater

The result would be :
{{“AXIdentifier”, missing value}, {“AXEnabled”, true}, {“AXFrame”, {0, 0, 356, 19}}, {“AXParent”, menu “Inspecteur” of menu item “Inspecteur” of menu “Présentation” of menu bar item “Présentation” of menu bar 1 of application process “Numbers” of application “System Events”}, {“AXSize”, {356, 19}}, {“AXMenuItemCmdGlyph”, missing value}, {“AXRole”, “AXMenuItem”}, {“AXMenuItemPrimaryUIElement”, missing value}, {“AXMenuItemCmdModifiers”, 8}, {“AXPosition”, {0, 0}}, {“AXTitle”, “Formater”}, {“AXHelp”, missing value}, {“AXMenuItemCmdChar”, missing value}, {“AXRoleDescription”, “commande de menu”}, {“AXSelected”, false}, {“AXMenuItemCmdVirtualKey”, missing value}, {“AXMenuItemMarkChar”, “✓”}}

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 17 mars 2020 20:10:39

Here are some examples of how we may grab the localized strings in “annoying” cases where English and/or French spelling isn’t available.
It strikes quite often with iWork applications under 10.13.6.
It may be worse for older systems.
This is why, sometimes I don’t use the localized string but the index of the item knowing that the iWork’s applications running under 10.13.6 or older systems will not change.

----------------------------------------------------------------
use AppleScript version "2.5"
use framework "Foundation"
use scripting additions
----------------------------------------------------------------

set thisLocale to current application's NSLocale's currentLocale()
-- set langX to thisLocale's localeIdentifier as string --> "fr_FR"
set lang2 to thisLocale's languageCode as text --> "fr"

set sys2 to (system attribute "sys2") as integer

tell application "Numbers"
	activate
	set x to "View"
	set loc to localized string x from table "TSApplication" --> "Présentation"
	if (sys2 < 14) and loc = x then
		if lang2 = "en" then
			set loc to "View"
		else if lang2 = "fr" then
			set loc to "Présentation"
		end if
	end if
	set viewN_loc to loc
	log result --> "Présentation"
	
	set x to "295.title"
	set loc to localized string x from table "MainMenu" --> "295.title"
	if (sys2 < 14) and loc = x then
		if lang2 = "en" then
			set loc to "View"
		else if lang2 = "fr" then
			set loc to "Présentation" -- really used
		end if
	end if
	set view295N_loc to loc
	log result --> "Présentation"
	
	set x to "296.title"
	set loc to localized string x from table "MainMenu" --> "296.title"
	if (sys2 < 14) and loc = x then
		if lang2 = "en" then
			set loc to "View"
		else if lang2 = "fr" then
			set loc to "Présentation" -- really used
		end if
	end if
	set view296N_loc to loc
	log result --> "Présentation"
	
	set x to "400617.title"
	set loc to localized string x from table "MainMenu" --> "400617.title"
	if (sys2 < 14) and loc = x then
		if lang2 = "en" then
			set loc to "Export to"
		else if lang2 = "fr" then
			set loc to "Exporter vers" -- really used
		end if
	end if
	set export400617_loc to loc
	log result --> "Exporter vers"
	
	set x to "942.title"
	set loc to localized string x from table "MainMenu" --> "942.title"
	if (sys2 < 14) and loc = x then
		if lang2 = "en" then
			set loc to "Export to"
		else if lang2 = "fr" then
			set loc to "Exporter vers" -- really used
		end if
	end if
	set export942_loc to loc
end tell
log result --> "Exporter vers"


tell application "Keynote"
	activate
	set x to "View"
	set loc to localized string x from table "TSApplication" --> "Présentation"
	if (sys2 < 14) and loc = x then
		if lang2 = "en" then
			set loc to "View"
		else if lang2 = "fr" then
			set loc to "Présentation"
		end if
	end if
	set viewK_loc to loc
	log result --> "Présentation"
	
	set x to "295.title"
	set loc to localized string x from table "MainMenu"
	log loc
	if (sys2 < 14) and loc = x then
		if lang2 = "en" then
			set loc to "View"
		else if lang2 = "fr" then
			set loc to "Présentation"
		end if
	end if
	set view295K_loc to loc
	log result --> "Présentation"
	
	set x to "296.title"
	set loc to localized string x from table "MainMenu" --> "296.title"
	if (sys2 < 14) and loc = x then
		if lang2 = "en" then
			set loc to "View"
		else if lang2 = "fr" then
			set loc to "Présentation"
		end if
	end if
	set view296K_loc to loc
	log result --> "Présentation"
	
	set x to "135.title"
	set loc to localized string x from table "KNMacPrintController" --> "135.title"
	if (sys2 < 14) and loc = x then
		if lang2 = "en" then
			set loc to "View"
		else if lang2 = "fr" then
			set loc to "Présentation"
		end if
	end if
	set view135K_loc to loc
	log result --> "Présentation"
	
	set x to "138.title"
	set loc to localized string x from table "KNMacPrintController" --> "138.title"
	log loc
	if (sys2 < 14) and loc = x then
		if lang2 = "en" then
			set loc to "View"
		else if lang2 = "fr" then
			set loc to "Présentation"
		end if
	end if
	set view138K_loc to loc
	log result --> "Présentation"
	
	set x to "140.title"
	set loc to localized string x from table "KNMacPrintController" --> "140.title"
	if (sys2 < 14) and loc = x then
		if lang2 = "en" then
			set loc to "View"
		else if lang2 = "fr" then
			set loc to "Présentation"
		end if
	end if
	set view140K_loc to loc
	log result --> "Présentation"
	
	set x to "1543.title"
	set loc to localized string x from table "MainMenu" --> "1543.title"
	if (sys2 < 14) and loc = x then
		if lang2 = "en" then
			set loc to "Export to"
		else if lang2 = "fr" then
			set loc to "Exporter vers"
		end if
	end if
	set export1543_loc to loc
	log result --> "Exporter vers"
	
	set x to "1780.title"
	set loc to localized string x from table "MainMenu" --> "1780.title"
	if (sys2 < 14) and loc = x then
		if lang2 = "en" then
			set loc to "Export to"
		else if lang2 = "fr" then
			set loc to "Exporter vers"
		end if
	end if
	set export1780_loc to loc
	log result --> "Exporter vers"
end tell

{viewN_loc, view295N_loc, view296N_loc, export400617_loc, export942_loc, linefeed, viewK_loc, view295K_loc, view296K_loc, view135K_loc, view138K_loc, view140K_loc, export1543_loc, export1780_loc}

As you may see, I choose to waste some space in exchange with the ability to copy paste
set loc to localized string x from table “MainMenu” → “1780.title”
if (sys2 < 14) and loc = x then
if lang2 = “en” then
set loc to “Export to”
else if lang2 = “fr” then
set loc to “Exporter vers”
end if
end if
having only two strings to edit.
Maybe you didn’t knew that I am lazy.

Back to your projects I must say that, at this time, I never found a way to grab infos upon UI elements like pictures, shapes, charts, tables, cells…
Of course, I don’t know if something evolved about that in “recent” versions.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 17 mars 2020 21:27:36

Smile…

I have never seen that one before AXMenuItemPrimaryUIElement or AXMenuItemCmdVirtualKey…


I couldn’t remember when I use Swedish language on my computer. I do remember my sister
got company computer with Microsoft Works in Swedish, yes it true… I had PC, but I also use Linux on that machine DX486 with 4mb ram. I could run XWindow on that machine, login as second user to do some task, and do switching between. It was very powerful compare to Microsoft dos.

I have read a couple of Swedish books about computers its truly a nightmare.

Yvan do you have any great idea about random position with x,y. ??

I did some test but it was not good at all.

What are you wanting to know about random position with x,y ?
Is it something like

tell application "System Events" to tell process "Finder"
	set frontmost to true
	set {x, y} to my randomPosition()
	log {x, y}
	click at {x, y}
end tell

on randomPosition()
	set xRandom to random number from 1 to 1920
	set yRandom to random number from 1 to 1080
	return {xRandom, yRandom}
end randomPosition

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 17 mars 2020 22:35:01

You could get the Chart here. all checkbox are in toolbar.
from 1 - 9, radio group the 2 radio button on the right.

tell window 1 to tell toolbar 1 to tell group 6
		click checkbox 1
		tell checkbox 1
			--> {pop over}
			tell pop over 1
				--> {button, button, button, button, button, button, button, button, button, button, button, button, button, UI element, button, button, radio group}
				tell radio group 1
					-- class of UI elements
					-- get its name of every radio button
					--> {"2D", "3D", "Interactive"}
				end tell
				get its properties of every UI element
				click button 15
				tell UI element 1
					-- click
					get its properties
				end tell
			end tell
		end tell
	end tell

Thanks Yvan.

The idea is this…

Params: Amount of shapes
Params: Size of Shapes
Params: Reflection
Params: Options (Fill,Border,Shadow) → This need to be GUI Scripting.

I also thinking about random rotation with range -5 - 5 degrees

make new shape with properties {position{randomPosX,RandomPosY}}

With your very late message things become more clear. Maybe they will be really clear tomorrow when I will really look at the script.

Have a good night.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 17 mars 2020 23:12:42

Thanks Yvan, Good night to you 2.

I test your latest code, close… sometimes the shape come to close to other.
So I’m think I need a offset…

Regards.

This is what I want to do.

Random shape on a sheet, if the sheet is 3x5 in other words 15 cells.

1 shape per cell, and max shape of 15.

but if amount of shapes are 7 it will still be 1 shape per cell.

https://filebin.net/0ztt91h6sou90d2w

Late night yesterday I made a quick test to get values of positions x,y

If you run this code it will give you a random number between 0-42

The reference sheet is 3x5, with a size of 425, 709 for A4
The shape size could be any number of 100 to 142

I include in this code fixed random list of first column in the sheet.
As you could see the first cell of first column use {0-42,0-42}
second cell of first column use {142-184,0-42} and the last use {284-326,0-42}

Maybe it could be helpful to understand how I think.

property shapePosX : 600
property shapePosY : 0
property shapeHeight : 142
property shapeWidth : 142
property shapeRotation : 5
property shapeOpacity : 95
property shapeReflection : 20

set tableSize to {425, 709} --> Should feet A4 format

-- set random value as list for test
set fc_radPos1 to {5, 10, 15, 20, 25, 30, 35, 40}
set fc_radPos2 to {140, 145, 150, 155, 160, 165, 170, 175, 180, 185}
set fc_radPos3 to {285, 290, 295, 300, 305, 310, 315, 320, 325}

-- Count items in the list.
set fc_rC1 to count fc_radPos1 --> 8

-- Get the first value and the last.
set fc_rV1 to get the first item of fc_radPos1 & the last item of fc_radPos1

-- randomIndexFromList
return randomIndexFromList(fc_rC1, (get item 1 of fc_rV1), (get item 2 of fc_rV1))

-- makeShapeWithPos(25, 585)


-- Row & Column size 142pt
-- Shape size (100-142)x(100-142)pt

-- First Column
-- makeShapeWithPos(0-42, 0-42)
-- makeShapeWithPos(142-184, 0-42)
-- makeShapeWithPos(284-326, 0-42)

-- Second Column
-- makeShapeWithPos(0-42, 142-184)
-- makeShapeWithPos(142-184, 142-184)
-- makeShapeWithPos(284-326, 142-184)

-- Third Column
-- makeShapeWithPos(0-42, 284-326)
-- makeShapeWithPos(142-184, 284-326)
-- makeShapeWithPos(284-326, 284-326)

-- Fourth Column
-- makeShapeWithPos(0-42, 426-468)
-- makeShapeWithPos(142-184, 426-468)
-- makeShapeWithPos(284-326, 426-468)

-- Fifth Column
-- makeShapeWithPos(0-42, 568-610)
-- makeShapeWithPos(142-184, 568-610)
-- makeShapeWithPos(284-326, 568-610)


on randomPosition()
	set xRandom to random number from 20 to 300
	set yRandom to random number from 20 to 586
	return {xRandom, yRandom}
end randomPosition

on randomIndexFromList(_countItems, _firstItem, _lastItem)
	set theList to {}
	repeat until (count theList) = _countItems
		set r to (random number from _firstItem to _lastItem)
		if theList does not contain {r} then set end of theList to r
	end repeat
	set theNumber to last item of theList as integer
	return theNumber
end randomIndexFromList

on makeShapeWithPos(xPos, yPos)
	tell application "Numbers" to tell sheet 1 of document 1
		return make new shape with properties {position:{xPos, yPos}, width:shapeWidth, height:shapeHeight}
	end tell
end makeShapeWithPos

(*
set theList to {}
repeat until (count theList) = theCount
	set r to (random number from 1 to theCount)
	if theList does not contain {r} then set end of theList to r
end repeat
*)
-- set theRandomNumber to first item of theList as integer

(*
tell application "System Events" to tell application process "Numbers"
	set frontmost to true
	tell window 1 to tell scroll area 3
		class of UI elements
		get its properties of every UI element
		-----------------------
		tell pop up button 1
			click
			tell menu 1
				set menuItem to its name of every menu item
				--> {"No Fill", "Colour Fill", "Gradient Fill", "Advanced Gradient Fill", "Image Fill", "Advanced Image Fill"}
				click menu item "Image Fill"
			end tell
		end tell
		-----------------------
		tell pop up button 2
			click
			tell menu 1
				get its name of every menu item
				--> {"Original Size", "Stretch", "Tile", "Scale to Fill", "Scale to Fit"}
				click menu item "Scale to Fill"
			end tell
		end tell
		-----------------------
		tell pop up button 3
			click
			tell menu 1
				get its name of every menu item
				--> {"No Border", "Line", "Picture Frame"}
				click menu item "Picture Frame"
			end tell
		end tell
		-----------------------
		
	end tell
end tell
*)

I then set the item 1 of the handler to x position and item 2 of handler to y position

-- set random value as list for test
set {fc1_min, fc1_max} to {5, 40}
set {fc2_min, fc2_max} to {140, 185}
set {fc3_min, fc3_max} to {285, 325}

-- randomIndexFromList 
set shapefc1 to randomIndexFromList(2, fc1_min, fc1_max)

I did some change in this handler to return 2 value

on randomIndexFromList(_countItems, _firstItem, _lastItem)
	set theList to {}
	repeat until (count theList) = _countItems
		set r to (random number from _firstItem to _lastItem)
		if theList does not contain {r} then set end of theList to r
	end repeat
	set theNumber to first item of theList & last item of theList
	return theNumber
end randomIndexFromList

Yvan, now I getting closer to random positions with shape.

What do you think ??

Ps. The code is still tests…

Regards

property shapePosX : 600
property shapePosY : 0
property shapeHeight : 125
property shapeWidth : 125
property shapeRotation : 5
property shapeOpacity : 95
property shapeReflection : 20

set tableSize to {125, 709} --> Should feet A4 format

-------- First column ------------
-- set the range for Row to test
set {row1_min, row1_max} to {-10, 60}
set {row2_min, row2_max} to {140, 190}
set {row3_min, row3_max} to {280, 330}

-- set the range of column 1 for test
set {c1_min, c1_max} to {-10, 60}

----------------------------------

-- set the range of column 2 for text
set {c2_min, c2_max} to {140, 190}

-- set the range of column 3 for text
set {c3_min, c3_max} to {284, 326}

-- set the range of column 4 for test
set {c4_min, c4_max} to {426, 468}

-- set the range of column 5 for test
set {c5_min, c5_max} to {568, 610}

-- Column1
makeShapeWithPos(item 1 of randomIndexFromList(2, row1_min, row1_max), ¬
	item 2 of (randomIndexFromList(2, c1_min, c1_max)))
makeShapeWithPos(item 1 of randomIndexFromList(2, row2_min, row2_max), ¬
	item 2 of (randomIndexFromList(2, c1_min, c1_max)))
makeShapeWithPos(item 1 of randomIndexFromList(2, row3_min, row3_max), ¬
	item 2 of (randomIndexFromList(2, c1_min, c1_max)))

-- Column 3
makeShapeWithPos(item 1 of randomIndexFromList(2, row1_min, row1_max), ¬
	item 2 of (randomIndexFromList(2, c3_min, c3_max)))
makeShapeWithPos(item 1 of randomIndexFromList(2, row2_min, row2_max), ¬
	item 2 of (randomIndexFromList(2, c3_min, c3_max)))
makeShapeWithPos(item 1 of randomIndexFromList(2, row3_min, row3_max), ¬
	item 2 of (randomIndexFromList(2, c3_min, c3_max)))

-- Column 5
makeShapeWithPos(item 1 of randomIndexFromList(2, row1_min, row1_max), ¬
	item 2 of (randomIndexFromList(2, c5_min, c5_max)))
makeShapeWithPos(item 1 of randomIndexFromList(2, row2_min, row2_max), ¬
	item 2 of (randomIndexFromList(2, c5_min, c5_max)))
makeShapeWithPos(item 1 of randomIndexFromList(2, row3_min, row3_max), ¬
	item 2 of (randomIndexFromList(2, c5_min, c5_max)))

-- Row & Column size 142pt
-- Shape size (100-142)x(100-142)pt

-- First Column
-- makeShapeWithPos(0-42, 0-42)
-- makeShapeWithPos(142-184, 0-42)
-- makeShapeWithPos(284-326, 0-42)

-- Second Column
-- makeShapeWithPos(0-42, 142-184)
-- makeShapeWithPos(142-184, 142-184)
-- makeShapeWithPos(284-326, 142-184)

-- Third Column
-- makeShapeWithPos(0-42, 284-326)
-- makeShapeWithPos(142-184, 284-326)
-- makeShapeWithPos(284-326, 284-326)

-- Fourth Column
-- makeShapeWithPos(0-42, 426-468)
-- makeShapeWithPos(142-184, 426-468)
-- makeShapeWithPos(284-326, 426-468)

-- Fifth Column
-- makeShapeWithPos(0-42, 568-610)
-- makeShapeWithPos(142-184, 568-610)
-- makeShapeWithPos(284-326, 568-610)


on randomPosition()
	set xRandom to random number from 20 to 300
	set yRandom to random number from 20 to 586
	return {xRandom, yRandom}
end randomPosition

on randomIndexFromList(_countItems, _firstItem, _lastItem)
	set theList to {}
	repeat until (count theList) = _countItems
		set r to (random number from _firstItem to _lastItem)
		if theList does not contain {r} then set end of theList to r
	end repeat
	set theNumber to first item of theList & last item of theList
	return theNumber
end randomIndexFromList

on makeShapeWithPos(xPos, yPos)
	tell application "Numbers" to tell sheet 1 of document 1
		return make new shape with properties {position:{xPos, yPos}, width:shapeWidth, height:shapeHeight}
	end tell
end makeShapeWithPos

(*
set theList to {}
repeat until (count theList) = theCount
	set r to (random number from 1 to theCount)
	if theList does not contain {r} then set end of theList to r
end repeat
*)
-- set theRandomNumber to first item of theList as integer

(*
tell application "System Events" to tell application process "Numbers"
	set frontmost to true
	tell window 1 to tell scroll area 3
		class of UI elements
		get its properties of every UI element
		-----------------------
		tell pop up button 1
			click
			tell menu 1
				set menuItem to its name of every menu item
				--> {"No Fill", "Colour Fill", "Gradient Fill", "Advanced Gradient Fill", "Image Fill", "Advanced Image Fill"}
				click menu item "Image Fill"
			end tell
		end tell
		-----------------------
		tell pop up button 2
			click
			tell menu 1
				get its name of every menu item
				--> {"Original Size", "Stretch", "Tile", "Scale to Fill", "Scale to Fit"}
				click menu item "Scale to Fill"
			end tell
		end tell
		-----------------------
		tell pop up button 3
			click
			tell menu 1
				get its name of every menu item
				--> {"No Border", "Line", "Picture Frame"}
				click menu item "Picture Frame"
			end tell
		end tell
		-----------------------
		
	end tell
end tell
*)

This version I have include random rotation as third argument in makeShapeWithPos handler.

property shapePosX : 600
property shapePosY : 0
property shapeHeight : 125
property shapeWidth : 125
property shapeOpacity : 95
property shapeReflection : 20

set tableSize to {125, 709} --> Should feet A4 format

-------- Row Range -------------
-- set the range for Row to test
set {row1_min, row1_max} to {-25, 65}
set {row2_min, row2_max} to {110, 220}
set {row3_min, row3_max} to {250, 360}


-------- Column 1 Range ---------
-- set the range of column 1 for test
set {c1_min, c1_max} to {-20, 50}

-------- Column 2 Range ---------
-- set the range of column 2 for text
set {c2_min, c2_max} to {100, 190}

-------- Column 3 Range ---------
-- set the range of column 3 for text
set {c3_min, c3_max} to {240, 335}

-------- Column 4 Range ---------
-- set the range of column 4 for test
set {c4_min, c4_max} to {390, 480}

-------- Column 5 Range ---------
-- set the range of column 5 for test
set {c5_min, c5_max} to {530, 610}


-- Column1
makeShapeWithPos(randomIndexFromList(2, row1_min, row1_max), randomIndexFromList(2, c1_min, c1_max), my shapeRotation())
-- makeShapeWithPos(randomIndexFromList(2, row2_min, row2_max), randomIndexFromList(2, c1_min, c1_max))
-- makeShapeWithPos(randomIndexFromList(2, row3_min, row3_max), randomIndexFromList(2, c1_min, c1_max))

-- Column2
-- makeShapeWithPos(randomIndexFromList(2, row1_min, row1_max), randomIndexFromList(2, c2_min, c2_max))
makeShapeWithPos(randomIndexFromList(2, row2_min, row2_max), randomIndexFromList(2, c2_min, c2_max), my shapeRotation())
-- makeShapeWithPos(randomIndexFromList(2, row3_min, row3_max), randomIndexFromList(2, c2_min, c2_max))

-- Column 3
makeShapeWithPos(randomIndexFromList(2, row1_min, row1_max), randomIndexFromList(2, c3_min, c3_max), my shapeRotation())
-- makeShapeWithPos(randomIndexFromList(2, row2_min, row2_max), randomIndexFromList(2, c3_min, c3_max))
-- makeShapeWithPos(randomIndexFromList(2, row3_min, row3_max), randomIndexFromList(2, c3_min, c3_max))

-- Column4
-- makeShapeWithPos(randomIndexFromList(2, row1_min, row1_max), randomIndexFromList(2, c4_min, c4_max))
-- makeShapeWithPos(randomIndexFromList(2, row2_min, row2_max), randomIndexFromList(2, c4_min, c4_max))
makeShapeWithPos(randomIndexFromList(2, row3_min, row3_max), randomIndexFromList(2, c4_min, c4_max), my shapeRotation())

-- Column 5
makeShapeWithPos(randomIndexFromList(2, row1_min, row1_max), randomIndexFromList(2, c5_min, c5_max), my shapeRotation())
-- makeShapeWithPos(randomIndexFromList(2, row2_min, row2_max), randomIndexFromList(2, c5_min, c5_max))
-- makeShapeWithPos(randomIndexFromList(2, row3_min, row3_max), randomIndexFromList(2, c5_min, c5_max))

-- Row & Column size 142pt
-- Shape size (100-142)x(100-142)pt

-- First Column
-- makeShapeWithPos(0-42, 0-42)
-- makeShapeWithPos(142-184, 0-42)
-- makeShapeWithPos(284-326, 0-42)

-- Second Column
-- makeShapeWithPos(0-42, 142-184)
-- makeShapeWithPos(142-184, 142-184)
-- makeShapeWithPos(284-326, 142-184)

-- Third Column
-- makeShapeWithPos(0-42, 284-326)
-- makeShapeWithPos(142-184, 284-326)
-- makeShapeWithPos(284-326, 284-326)

-- Fourth Column
-- makeShapeWithPos(0-42, 426-468)
-- makeShapeWithPos(142-184, 426-468)
-- makeShapeWithPos(284-326, 426-468)

-- Fifth Column
-- makeShapeWithPos(0-42, 568-610)
-- makeShapeWithPos(142-184, 568-610)
-- makeShapeWithPos(284-326, 568-610)

(*
on randomPosition()
	set xRandom to random number from 20 to 300
	set yRandom to random number from 20 to 586
	return {xRandom, yRandom}
end randomPosition
*)

on randomIndexFromList(_countItems, _firstItem, _lastItem)
	set theList to {}
	repeat until (count theList) = _countItems
		set r to (random number from _firstItem to _lastItem)
		if theList does not contain {r} then set end of theList to r
	end repeat
	set theNumber to last item of theList
	return theNumber
end randomIndexFromList

on makeShapeWithPos(xPos, yPos, shapeRotation)
	tell application "Numbers" to tell sheet 1 of document 1
		return make new shape with properties {position:{xPos, yPos}, width:shapeWidth, height:shapeHeight, rotation:shapeRotation}
	end tell
end makeShapeWithPos

on shapeRotation()
	set theList to {}
	repeat until (count theList) = 14
		set {min, max} to {-7, 7}
		set r to (random number from min to max)
		if theList does not contain {r} then set end of theList to r
	end repeat
	set theresult to last item of theList
	return theresult as integer
end shapeRotation


(*
set theList to {}
repeat until (count theList) = theCount
	set r to (random number from 1 to theCount)
	if theList does not contain {r} then set end of theList to r
end repeat
*)
-- set theRandomNumber to first item of theList as integer

(*
tell application "System Events" to tell application process "Numbers"
	set frontmost to true
	tell window 1 to tell scroll area 3
		class of UI elements
		get its properties of every UI element
		-----------------------
		tell pop up button 1
			click
			tell menu 1
				set menuItem to its name of every menu item
				--> {"No Fill", "Colour Fill", "Gradient Fill", "Advanced Gradient Fill", "Image Fill", "Advanced Image Fill"}
				click menu item "Image Fill"
			end tell
		end tell
		-----------------------
		tell pop up button 2
			click
			tell menu 1
				get its name of every menu item
				--> {"Original Size", "Stretch", "Tile", "Scale to Fill", "Scale to Fit"}
				click menu item "Scale to Fill"
			end tell
		end tell
		-----------------------
		tell pop up button 3
			click
			tell menu 1
				get its name of every menu item
				--> {"No Border", "Line", "Picture Frame"}
				click menu item "Picture Frame"
			end tell
		end tell
		-----------------------
		
	end tell
end tell
*)

There is an oddity in some instructions.


on randomIndexFromList(_countItems, _firstItem, _lastItem)
   set theList to {}
   repeat until (count theList) = _countItems
       set r to (random number from _firstItem to _lastItem)
      --  if theList does not contain {r} then set end of theList to r -- original
       if theList does not contain r then set end of theList to r -- theList contain values, not lists
   end repeat
   set theNumber to last item of theList
   return theNumber
end randomIndexFromList

on makeShapeWithPos(xPos, yPos, shapeRotation)
   tell application "Numbers" to tell sheet 1 of document 1
       return make new shape with properties {position:{xPos, yPos}, width:shapeWidth, height:shapeHeight, rotation:shapeRotation}
   end tell
end makeShapeWithPos

on shapeRotation()
   set theList to {}
   repeat until (count theList) = 14
       set {min, max} to {-7, 7}
       set r to (random number from min to max)
      --  if theList does not contain {r} then set end of theList to r -- original
       if theList does not contain r then set end of theList to r -- theList contain values, not lists
   end repeat
   set theresult to last item of theList
   return theresult as integer
end shapeRotation


(*
set theList to {}
repeat until (count theList) = theCount
   set r to (random number from 1 to theCount)
      --  if theList does not contain {r} then set end of theList to r -- original
       if theList does not contain r then set end of theList to r -- theList contain values, not lists
end repeat
*)

On my side I started building a script creating the table to work with.

You may use the button allowing you to send me a private message.
Using this channel would prevent us to waste space in the thread.
We would pass only stable steps.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 18 mars 2020 13:46:39