Pages: search and replace applescript

Yvan,

I did some research on this for you.

The reason this refuses to work in versions of OS X before 10.5 is that since “Å¿” is a Unicode character, and in AppleScript 1.x, which shipped with Tiger and earlier versions of Mac OS, text processing was done by the compiler in ASCII, the AppleScript compiler can’t handle the “Å¿” character.

You must have AppleScript 2.x to make this script work, which means you will have to have a copy of Leopard or later, I’m sorry to have to say.

Good luck, tho’.

-AJBlue98

Jerome,

I think your comment about the replacements not making much Å¿enÅ¿e/this not being for EngliÅ¿h conÅ¿umption Å¿hould have been directed at me, Å¿o I’m going to reÅ¿pond, if I may.

This is indeed meant for EngliÅ¿h conÅ¿umption. The practice Å¿tarted to decline around 1790 and ultimately died out in the late 1800s, but it uÅ¿ed to be that a long “s” (or “Å¿”) was uÅ¿ed except at the ends of words or where it might be confuÅ¿ing to look at (next to a lowercaÅ¿e “f” or lowercase, italic “g,” for inÅ¿tance). Since, during that period, typographers had to hand-Å¿et every page, and dealing with the extra haÅ¿Å¿les of having two forms for the lowercaÅ¿e “s” ultimately became too much of a bother, they began to phaÅ¿e out the long “Å¿.”

However, with the advent of modern computers, fonts that automatically Å¿elect appropriate ligatures, and the Unicode character Å¿et Å¿tandard including long “Å¿,” (and Å¿ince I found the exact rules for this online in mid-December), I have decided to bring the long “Å¿” back.

The Å¿cript (which I have updated again, below) is only half of the project (to convert my old Å¿hort “s” documents to long “Å¿”), and the other half of the project is the Unicode keyboard layout which I have created, which Å¿elects the appropriate “s” as the words are typed.

Hope that helps!

-AJBlue98


(*
This ſcript changes 20th Century-ſtyle type to 1776-era ſtandards with regards to the uſe of long "ſ."

Written by Jerome at MacScripter with input from AJBlue98.
http://macscripter.net/viewtopic.php?id=23896

Update: 6 Feb 2009 by AJBlue98
Changed exclusion list to inclusion list and added support for compound words resulting in a triple "s."
*)

set inclusionList to {"a", "b", "c", "d", "e", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
set tripleYesFactor to false

tell application "Pages"
	activate
	with timeout of 300 seconds --5 minutes
		tell body text of document 1
			set offsetList to character offset of every character whose contents is "s"
			repeat with anOffset in offsetList
				if contents of character (anOffset - 1) is "Å¿" and contents of character (anOffset + 1) is "s" then set tripleYesFactor to true
				if contents of character (anOffset - 1) is not "f" and contents of character (anOffset + 1) is in inclusionList and tripleYesFactor is false then
					set theCharacter to character (anOffset)
					if (ASCII number of theCharacter) is 115 then set character (anOffset) to "Å¿" --lowercase "s" = ascii number 115
				end if
				set tripleYesFactor to false
			end repeat
		end tell
	end timeout
end tell

Cheers!

-AJBlue98

The problem with Macos X 10.4.11 has no relation with Unicode.

It strikes on the bare script:


tell application "Pages"
   activate
   with timeout of 300 seconds --5 minutes
       tell body text of document 1
           set offsetList to character offset of every character whose contents is "s"
        end tell
   end timeout
end tell

which is not using Unicode.

Yvan KOENIG (from FRANCE vendredi 6 février 2009 09:47:48)