Changing properties for a pages text box

Hi,

Trying to send a text box on pages from the foreground, to the back ground thru applescript, but not using GUI scripting… tracked down a property in graphic that appears to be the key… but unable to reset/change it.

Document already contains a text box? Anybody?


tell application "Pages"
	tell document 1
		return properties of containing layer of graphic 1
		--{foreground:false, class:layer, master page:missing value} <- text box in foreground		
		--{foreground:true, class:layer, master page:missing value} <- text box in background
		set foreground of containing layer of graphic 1 to false (is true)
		--tell graphic 1
		--	set foreground of containing layer to false <- doesn't fail, doesn't succeed, does nothing it seems...
		--end tell
		return properties of containing layer of graphic
	end tell
end tell

Model: macpro
AppleScript: 2.2.1
Browser: Safari 536.11
Operating System: Mac OS X (10.7)

As I’m not sure that you are the asker to which I answered directly, here is my answer.


--[SCRIPT]
my activateGUIscripting()

tell application "Pages" to tell document 1
	set theBox to make new text box with properties {width:66, name:"top secret", stroke type:none, object text:"©Copyright", rotation:45.0, locked:0, text fit:rectangle, extra space:12.0, horizontal position:0, vertical position:0, height:22, placement:fixed, wrap:center, opacity:90.0}
end tell
(*
Trigger Arrange > Send Object to Background.
*)
my selectMenu("Pages", 7, 6)

tell application "Pages" to tell document 1
	containing layer of text box "top secret"
end tell

--=====

on activateGUIscripting()
	(* to be sure than GUI scripting will be active *)
	tell application "System Events"
		if not (UI elements enabled) then set (UI elements enabled) to true
	end tell
end activateGUIscripting

--=====
(*
==== Uses GUIscripting ==== 
*)
(*
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

--=====
--[/SCRIPT]

Yvan KOENIG (VALLAURIS, France) jeudi 5 juillet 2012 18:00:55

This works for me:

tell application "Pages"
	tell document 1
		set containingPage to containing page of text box 1
		if (containing layer of text box 1 is foreground layer of containingPage) then
			move text box 1 to end of background layer of containingPage
		end if
		select text box 1 -- If you want the box to become or remain selected.
	end tell
end tell

Edit: Or this phrasing, if you prefer:

tell application "Pages"
	tell document 1
		tell text box 1
			if (containing layer is foreground layer of containing page) then
				move to end of background layer of containing page
			end if
			select
		end tell
	end tell
end tell

Mr Garvey,

You are a genius! It works perfectly!! :smiley: