• 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: Make AppleScript Create an AppleWorks Spreadsheet?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Make AppleScript Create an AppleWorks Spreadsheet?


  • Subject: Re: Make AppleScript Create an AppleWorks Spreadsheet?
  • From: Yvan KOENIG <email@hidden>
  • Date: Wed, 12 Oct 2005 17:48:46 +0200


Le 10 oct. 2005 , à 14:56, Jonathan Levi MD a écrit :

Hi,

Would someone please help -- how to script AppleWorks's creating, say, a new 20-column x 10-row spreadsheet, without using System Events? (I've done it already using SE, but would rather do it without.)

Hello here is a script which do that except if you are using an old version (before 628) in which deleting an empty row activates the bad old eutocalc on strike bug.


-- [SCRIPT SS 20x20]

(*
Yvan KOENIG, Vallauris (FRANCE)
le 12 octobre 2005
*)

property french : false -- true = messages français, false = english messages
property versionOS : "" -- globale


property msg0 : "" -- globale
property msg99 : "" -- globale

on run
	try
		if msg0 is "" then my prepareMessages()
		set sansBug to my controlesDivers()
		set {nC, nR, nouveauDoc} to my initialisations()
		my redimensionne(nC, nR, nouveauDoc, sansBug)

	on error MsgErr number NroErr
		if NroErr is not -128 then
			beep 2
			tell application (path to frontmost application as string) to ¬
				display dialog "" & NroErr & " : " & MsgErr with icon 0 ¬
					buttons {msg99} giving up after 20
		end if
		return
	end try
end run

-- =============  Routines

on controlesDivers()
	set versionOS to my quelOS()
	tell application "AppleWorks 6"
		activate
		set vv to version as text
		if ("6." is not in vv) then ¬
			error msg0 number 8000
		(* Ce script n'est pas compatible
			avec cette version d‘AppleWorks.
• This script is not compatible
			with this version of  AppleWorks. *)

	end tell -- AppleWorks
	if (count of vv) > 5 then set vv to text -5 thru -1 of vv
	return ((vv = "6.2.8") or (vv = "6.2.9")) as boolean
end controlesDivers

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

on initialisations()
	tell application "AppleWorks 6"

		set {n_C, n_R} to {20, 20}

		set tDoc to spreadsheet document
		set le_Doc to make new document with properties ¬
			{name:("™.cwk"), document kind:tDoc}
		select document 1
		set nouveau_Doc to (name of document 1) as text
	end tell -- AppleWorks
	return {n_C, n_R, nouveau_Doc}
end initialisations

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

on redimensionne(Cn, Rn, nDoc, sbug)
	tell application "AppleWorks 6"
		select document nDoc
		tell document nDoc
			set Cn2 to count of columns (* 40 *)
			set Rn2 to count of rows (* 500 *)

			if Cn2 is less than Cn then
				repeat while Cn2 is less than Cn
					(* tant qu'il manque des colonnes *)
					set nbC to Cn - Cn2
					if nbC is greater than (Cn2 - 1) then set nbC to (Cn2 - 1)
					(* -1 sinon ça ajoute des rangées *)
					select (columns 1 thru nbC)
					select menu item 14 of menu 4
					(* insérer des cellules pour ajouter des colonnes *)
					set Cn2 to count of columns
				end repeat
			else if Cn2 is greater than Cn then
				repeat while Cn2 is greater than Cn
					(* tant qu'il y a trop de colonnes *)
					set nbC to Cn2 - Cn
					if nbC is greater than (Cn2 - 1) then set nbC to (Cn2 - 1)
					(* -1 sinon ça ajoute des rangées *)
					select (columns 1 thru nbC)
					select menu item 15 of menu 4
					(* supprimer des cellules  pour supprimer des colonnes*)
					set Cn2 to count of columns
				end repeat
			end if

			if Rn2 is less than Rn then
				repeat while Rn2 is less than Rn
					(* tant qu'il manque des rangées *)
					set nbR to Rn - Rn2
					if nbR is greater than Rn2 then set nbR to Rn2
					select (rows 1 thru nbR)
					select menu item 14 of menu 4
					(* insérer des cellules pour ajouter des rangées *)
					set Rn2 to count of rows
				end repeat
			else if Rn2 is greater than Rn then
				if sbug is true then
					repeat while Rn2 is greater than Rn
						(* tant qu'il y a trop de rangées *)
						set nbR to Rn2 - Rn
						if nbR is greater than Rn2 then set nbR to Rn2
						select (rows 1 thru nbR)
						select menu item 15 of menu 4
						(* supprimer des cellules pour supprimer des rangées *)
						set Rn2 to count of rows
					end repeat
				end if -- sBug
				(* si ce n'est pas 628 ou 629
on ne supprime pas les rangées superflues (bug recalcul) *)
			end if

		end tell -- document
	end tell -- AppleWorks
end redimensionne

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

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 prepareMessages()
	if french is true then
		set msg0 to "Ce script n’est pas compatible" & return & ¬
			"avec cette version d’AppleWorks." & return & ¬
			"Veuillez utiliser une version 6.x …"
		set msg99 to " Vu "
	else
		set msg0 to "This script is not compatible" & return & ¬
			"with this version of  AppleWorks." & return & ¬
			"Please use version 6.x ..."
		set msg99 to " Oops "
	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: 
 >Make AppleScript Create an AppleWorks Spreadsheet? (From: Jonathan Levi MD <email@hidden>)

  • Prev by Date: Re: mount volume, new error from out of the blue
  • Next by Date: Scripting iCal
  • Previous by thread: Re: Make AppleScript Create an AppleWorks Spreadsheet?
  • Next by thread: path name
  • Index(es):
    • Date
    • Thread