• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to 'do menu' to execute a TextEdit menu ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to 'do menu' to execute a TextEdit menu ?


  • Subject: Re: How to 'do menu' to execute a TextEdit menu ?
  • From: yvan-koenig <email@hidden>
  • Date: Mon, 7 Feb 2005 19:36:43 +0100

Bonjour Émile

-- [SCRIPT]

(*

Yvan KOENIG le 1 février 2005
*)

property french : true (* true = messages français
• false = english messages *)

property theApp : "TextEdit" --"Pages"

property msg1 : "" -- globale
property msg99 : "" -- globale
property gui99 : "" -- globale

on run
try
if my quelOS() is less than "1030" then error msg1 number 8001
my grasGUI()
-- my souligneGUI()
-- my italiqueGUI()
(* CAUTION, due to a bug in System Events, send cmd -q on french keyboards *)

on error MsgErr number NroErr
if NroErr is not -128 then
beep 2
tell application (my quiEstAuPremierPlan())
display dialog "" & NroErr & return & MsgErr with icon 0 ¬
buttons {" Vu "} giving up after 20
end tell -- application
end if
return
end try -- t1
end run


-- ==================

on GUImissing()
	tell application "System Preferences"
		activate
		set current pane to ¬
			pane "com.apple.preference.universalaccess"
		display dialog gui99
	end tell -- to System Preferences
end GUImissing

-- ==================

on keystrokesGUI(liste)
tell application "System Events"
if UI elements enabled then
set frontmost of process theApp to true
tell process theApp
repeat with k in liste
set ks to k as list (* for safe, useful for chars with no modifier *)
if (count of ks) is 1 then
keystroke (ks's item 1)
else if ks's item 2 is "c" then
keystroke (ks's item 1) using command down
else if ks's item 2 is "s" then
keystroke (ks's item 1) using shift down
else if ks's item 2 is "cs" then
keystroke (ks's item 1) using {shift down, command down}
end if
end repeat
end tell -- to process
else
my GUImissing()
end if
end tell -- to System Events
end keystrokesGUI


-- ==================

on fermeGUI()
	my keystrokesGUI({{"w", "c"}}) (* cmd - w *)
end fermeGUI

-- ==================

on imprimeGUI()
	my keystrokesGUI({{"p", "c"}, return}) (* cmd + p, return *)
end imprimeGUI

-- ==================

on italiqueGUI()
(* CAUTION, due to a bug in System Events, send cmd -q on french keyboards *)
my keystrokesGUI({{"i", "c"}}) (* cmd - i *)
end italiqueGUI


-- ==================

on grasGUI()
	my keystrokesGUI({{"b", "c"}}) (* cmd - b *)
end grasGUI

-- ==================

on souligneGUI()
	my keystrokesGUI({{"u", "c"}}) (* cmd - u *)
end souligneGUI


-- ==================

on controleGUI()
	tell application "System Events"
		if not UI elements enabled then my GUImissing()
	end tell -- to System Events
end controleGUI

-- ==================

on quelOS()
	try
		(* «event fndrgstl» = forme canonique de system attribute *)
		-- set hexData to «event fndrgstl» "sysv"
		set hexData to system attribute "sysv"
		set hexString to {}
		repeat 4 times
			set hexString to ((hexData mod 16) as string) & hexString
			set hexData to hexData div 16
		end repeat
		set OS_version to hexString as string
	on error
		set OS_version to "0000"
		(* retournera "0000" si "system attribute" n'est pas reconnu *)
	end try
	return OS_version
end quelOS

-- ==================

on quiEstAuPremierPlan()
(* «constant afdregfp» est la forme canonique de frontmost application *)
-- return (path to «constant afdregfp» as string)
return (path to frontmost application as string)
end quiEstAuPremierPlan


-- ==================

on prepareMessages()
if french is true then
set msg1 to "Ce script requiert la présence" & return & ¬
"de Mac OS 10.3 ou supérieur."
set msg99 to " Vu "
set gui99 to "Le scriptage des éléments d’interface est désactivé. " & ¬
"Cochez «Activez l’accès pour les périphériques d’aide»"
else
set msg1 to "This script must be used with" & return & ¬
"Mac OS 10.3 or higher."
set msg99 to " Oops "
set gui99 to "UI element scripting is not enabled. " & ¬
"Check “Enable access for assistive devices”"
end if
end prepareMessages


-- [/SCRIPT]

Yvan KOENIG

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >How to 'do menu' to execute a TextEdit menu ? (From: Emile Schwarz <email@hidden>)

  • Prev by Date: Re: AppleScript SOAP implementation
  • Next by Date: HOWTO check if file is completly copied - OS9
  • Previous by thread: How to 'do menu' to execute a TextEdit menu ?
  • Next by thread: HOWTO check if file is completly copied - OS9
  • Index(es):
    • Date
    • Thread