Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to remove all hyperlinks at once?

Hi guys,

I want to know how to remove all hyperlinks in a text at once. I know how to remove one link at a time. But it's time consuming if you paste a text with a lot of hyperlinks.

Thanks,

Adriano.

iMac 2.66 GHz 2 GB, Mac OS X (10.5.5)

Posted on Mar 14, 2009 11:36 AM

Reply
Question marked as Best reply

Posted on Mar 14, 2009 12:57 PM

Duplicate your document for safe then drag and drop the icon of the copy of the icon of this script saved as an application.

--[SCRIPT remove links]{code}
(*

Enregistrer le script en tant qu'Application ou Progiciel : remove links.app
Déposez le sur le bureau par exemple.
Glisser-déposer l'icône d'un document Pages sur celle du script
va éliminer tous les Hyperliens et signets prédsents dans le document.
On peut également qlisser déposer un fichier index.xml.

+++++++

Save the script as an Application or an Application Bundle: remove links.app
Store it on the desktop for instance.
Drag and drop the icon of a Pages document on the script's icon
to remove the Hyperlinks and Bookmarks embedded in the document.
We may also drag & drop an index.xml file.

Yvan KOENIG (Vallauris, FRANCE)
16 février 2009
enhanced 17 février 2009
*)
--=====

property removeBookmarks : true
(*
true = remove the bookmarks
false = don't remove the bookmarks *)
property removeLinks : true
(*
true = remove the Links
false = don't remove the Links *)
property liste : {}

--=====

on open (sel)

set theDoc to (item 1 of sel) as text

tell application "System Events" to tell disk item theDoc
set nn to name
set uti to type identifier
set isPackage to package folder
end tell

if nn is "index.xml" then
my traiteIndex(theDoc)
else if uti is not in {"com.apple.iwork.Pages.Pages", "com.apple.iwork.pages.sffpages"} then
error "Not a Pages document !"
else if isPackage then
-- here the document is a package
if theDoc ends with ":" then set theDoc to text 1 thru -2 of theDoc
tell application "Finder"
set the_index to (theDoc & ":index.xml")
set indexGzAvailable to exists file (the_index & ".gz")
set indexAvailable to exists file the_index
end tell -- Finder
if indexGzAvailable then
if indexAvailable then tell application "Finder" to delete file the_index
my expandIndex(the_index & ".gz")
my traiteIndex(the_index)
else
if indexAvailable then
my traiteIndex(the_index)
else
error "No Index available !"
end if
end if -- indexGzAvailable
else
-- here the document is a flat one
tell application "Finder"
set cont to (container of file theDoc) as text
set name of file theDoc to (nn & ".zip")
end tell -- Finder
set theDocZ to cont & nn & ".zip"
my expandDoc(theDocZ, theDoc)
tell application "Finder"
set name of file theDoc to (nn & "yk")
set theDocF to cont & nn & "yk"
set the_index to (theDocF & ":index.xml")
set indexAvailable to exists file the_index
end tell -- Finder
if indexAvailable then my traiteIndex(the_index)
end if -- nn …
end open

--=====

on traiteIndex(theIndex)
local theKey1, theKey2, theKey3, theKey4, theKey5, itm, itm1, itm2, itm2
my nettoie()
(* Lis le contenu du fichier Index.xml *)
set texte to read file theIndex from 1

if removeBookmarks then
(* supprime les descripteurs de signets *)
set theKey1 to "<sf:bookmark sf:name"
set theKey2 to "</sf:bookmark>"
if texte contains theKey1 then
set my liste to my decoupe(texte, theKey1)
repeat with i from 2 to count of my liste
set itm to my decoupe(item i of my liste, theKey2)
set itm1 to item 1 of itm
set itm1 to text (1 + (offset of ">" in itm1)) thru -1 of itm1
set itm2 to my recolle(items 2 thru -1 of itm, theKey2)
set item i of my liste to (itm1 & itm2)
end repeat -- i
set texte to my recolle(my liste, "")
end if
end if -- removeBookmarks
(*
Here are samples of Hyperlinks in the index.xml file
--link to bookmark
<sf:p sf:style="paragraph-style-32">
<sf:bookmark sf:name="page 3" sf:ranged="true" sf:page="3">
page 3
</sf:bookmark>
<sf:br/>

--link to URL
<sf:p sf:style="paragraph-style-32">
<sf:link href="http://discussions.apple.com/thread.jspa?threadID=1905618&amp;tstart=0" sf:style="SFWPCharacterStyle-7">
<sf:span sf:style="SFWPCharacterStyle-7">
Change cell color if number is different from previous cell
</sf:span>
</sf:link>
<sf:br/>

--link to an other Pages document
<sf:p sf:style="paragraph-style-32">
<sf:link href="pages:///Users/yvan_koenig/Documents/Sans%20titre%20-%20copie.pages#un%20 signet%20externe">
<sf:file-alias sf:file-alias="0000000001ae000200010c4d6163696e746f7368204844000000000000000000 000000000000c45c8cef482b00000008a77c1853616e73207469747265202d20636f7069652e7061 67657300000000000000000000000000000000000000000000000000000000000000000000000000 000000360f06c5c03419000000000000000000010002000009200000000000000000000000000000 0009446f63756d656e747300001000080000c45c70cf0000001100080000c5c0260900000001000c 0008a77c0008a76f00006bdf000200414d6163696e746f73682048443a55736572733a7976616e5f 6b6f656e69673a446f63756d656e74733a53616e73207469747265202d20636f7069652e70616765 7300000e0032001800530061006e00730020007400690074007200650020002d00200063006f0070 00690065002e00700061006700650073000f001a000c004d006100630069006e0074006f00730068 0020004800440012003455736572732f7976616e5f6b6f656e69672f446f63756d656e74732f5361 6e73207469747265202d20636f7069652e7061676573001300012f00001500020012ffff0000"/>
<sf:span sf:style="SFWPCharacterStyle-7">
vers autre document
</sf:span>
</sf:link>
<sf:br/>
*)
if removeLinks then
(* supprime les descripteurs de liens *)
set theKey1 to "<sf:link href="
set theKey3 to "<sf:span sf:style="
set theKey4 to "</sf:link>"
set theKey5 to "</sf:span>"
if texte contains theKey1 then
set my liste to my decoupe(texte, theKey1)
repeat with i from 2 to count of my liste
set itm to my decoupe(item i of my liste, theKey4)
set itm1 to item 2 of my decoupe(item 1 of itm, theKey3)
set itm1 to text (1 + (offset of ">" in itm1)) thru -1 of itm1
set itm1 to item 1 of my decoupe(itm1, theKey5)
set itm2 to my recolle(items 2 thru -1 of itm, theKey4)
set item i of my liste to (itm1 & itm2)
end repeat -- i
set texte to my recolle(my liste, "")
end if -- texte contains
(*
This piece of code takes care of a bug in the save as Pages '08 process.
A link to an other document is not completely disabled so the 'disabled' link remains blue.
The link is stored this way:
<sf:p sf:style="paragraph-style-32">
<sf:span sf:style="SFWPCharacterStyle-7">vers autre document</sf:span>
<sf:br/>

when it would be:
<sf:p sf:style="paragraph-style-32">
vers autre document
<sf:br/>
*)
if texte contains theKey3 then
set my liste to my decoupe(texte, theKey3)
repeat with i from 2 to count of my liste
set itm to my decoupe(item i of my liste, theKey5)
set itm1 to item 1 of itm
set itm1 to text (1 + (offset of ">" in itm1)) thru -1 of itm1
set itm2 to my recolle(items 2 thru -1 of itm, theKey5)
set item i of my liste to (itm1 & itm2)
end repeat -- i
set texte to my recolle(my liste, "")
end if -- texte contains
end if -- removeLinks

set lineFeed to ASCII character 10
if texte contains (lineFeed & lineFeed) then set texte to my recolle(my decoupe(texte, lineFeed & lineFeed), lineFeed)
if texte contains (return & return) then set texte to my recolle(my decoupe(texte, return & return), return)

set eof of file theIndex to 0
write texte to file theIndex

my nettoie()
end traiteIndex

--=====

on decoupe(t, d)
local l
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to ""
return l
end decoupe

--=====

on recolle(l, d)
local t
set AppleScript's text item delimiters to d
set t to l as text
set AppleScript's text item delimiters to ""
return t
end recolle

--=====

on nettoie()
set liste to {}
end nettoie

--=====

(* Expands the zip file z in the container d, z and d are pathnames as strings *)
on expandDoc(z, d)
do shell script "unzip " & quoted form of (POSIX path of (z)) & " -d " & quoted form of (POSIX path of (d))
end expandDoc

--=====

on expandIndex(f)
do shell script "gunzip " & quoted form of (POSIX path of (f))
end expandIndex

--=====

on lisIndex_xml(f)
local t
try
set t to ""
set t to (read file f)
end try
return t
end lisIndex_xml

--=====

on compactIndex(nDoc)
local aliasNDoc
set aliasNDoc to nDoc as alias
write leTexte to aliasNDoc starting at 0
do shell script "gzip " & quoted form of POSIX path of aliasNDoc
end compactIndex

--=====
--[/SCRIPT](code}

Yvan KOENIG (from FRANCE samedi 14 mars 2009 20:55:42)
3 replies
Question marked as Best reply

Mar 14, 2009 12:57 PM in response to cowpox

Duplicate your document for safe then drag and drop the icon of the copy of the icon of this script saved as an application.

--[SCRIPT remove links]{code}
(*

Enregistrer le script en tant qu'Application ou Progiciel : remove links.app
Déposez le sur le bureau par exemple.
Glisser-déposer l'icône d'un document Pages sur celle du script
va éliminer tous les Hyperliens et signets prédsents dans le document.
On peut également qlisser déposer un fichier index.xml.

+++++++

Save the script as an Application or an Application Bundle: remove links.app
Store it on the desktop for instance.
Drag and drop the icon of a Pages document on the script's icon
to remove the Hyperlinks and Bookmarks embedded in the document.
We may also drag & drop an index.xml file.

Yvan KOENIG (Vallauris, FRANCE)
16 février 2009
enhanced 17 février 2009
*)
--=====

property removeBookmarks : true
(*
true = remove the bookmarks
false = don't remove the bookmarks *)
property removeLinks : true
(*
true = remove the Links
false = don't remove the Links *)
property liste : {}

--=====

on open (sel)

set theDoc to (item 1 of sel) as text

tell application "System Events" to tell disk item theDoc
set nn to name
set uti to type identifier
set isPackage to package folder
end tell

if nn is "index.xml" then
my traiteIndex(theDoc)
else if uti is not in {"com.apple.iwork.Pages.Pages", "com.apple.iwork.pages.sffpages"} then
error "Not a Pages document !"
else if isPackage then
-- here the document is a package
if theDoc ends with ":" then set theDoc to text 1 thru -2 of theDoc
tell application "Finder"
set the_index to (theDoc & ":index.xml")
set indexGzAvailable to exists file (the_index & ".gz")
set indexAvailable to exists file the_index
end tell -- Finder
if indexGzAvailable then
if indexAvailable then tell application "Finder" to delete file the_index
my expandIndex(the_index & ".gz")
my traiteIndex(the_index)
else
if indexAvailable then
my traiteIndex(the_index)
else
error "No Index available !"
end if
end if -- indexGzAvailable
else
-- here the document is a flat one
tell application "Finder"
set cont to (container of file theDoc) as text
set name of file theDoc to (nn & ".zip")
end tell -- Finder
set theDocZ to cont & nn & ".zip"
my expandDoc(theDocZ, theDoc)
tell application "Finder"
set name of file theDoc to (nn & "yk")
set theDocF to cont & nn & "yk"
set the_index to (theDocF & ":index.xml")
set indexAvailable to exists file the_index
end tell -- Finder
if indexAvailable then my traiteIndex(the_index)
end if -- nn …
end open

--=====

on traiteIndex(theIndex)
local theKey1, theKey2, theKey3, theKey4, theKey5, itm, itm1, itm2, itm2
my nettoie()
(* Lis le contenu du fichier Index.xml *)
set texte to read file theIndex from 1

if removeBookmarks then
(* supprime les descripteurs de signets *)
set theKey1 to "<sf:bookmark sf:name"
set theKey2 to "</sf:bookmark>"
if texte contains theKey1 then
set my liste to my decoupe(texte, theKey1)
repeat with i from 2 to count of my liste
set itm to my decoupe(item i of my liste, theKey2)
set itm1 to item 1 of itm
set itm1 to text (1 + (offset of ">" in itm1)) thru -1 of itm1
set itm2 to my recolle(items 2 thru -1 of itm, theKey2)
set item i of my liste to (itm1 & itm2)
end repeat -- i
set texte to my recolle(my liste, "")
end if
end if -- removeBookmarks
(*
Here are samples of Hyperlinks in the index.xml file
--link to bookmark
<sf:p sf:style="paragraph-style-32">
<sf:bookmark sf:name="page 3" sf:ranged="true" sf:page="3">
page 3
</sf:bookmark>
<sf:br/>

--link to URL
<sf:p sf:style="paragraph-style-32">
<sf:link href="http://discussions.apple.com/thread.jspa?threadID=1905618&amp;tstart=0" sf:style="SFWPCharacterStyle-7">
<sf:span sf:style="SFWPCharacterStyle-7">
Change cell color if number is different from previous cell
</sf:span>
</sf:link>
<sf:br/>

--link to an other Pages document
<sf:p sf:style="paragraph-style-32">
<sf:link href="pages:///Users/yvan_koenig/Documents/Sans%20titre%20-%20copie.pages#un%20 signet%20externe">
<sf:file-alias sf:file-alias="0000000001ae000200010c4d6163696e746f7368204844000000000000000000 000000000000c45c8cef482b00000008a77c1853616e73207469747265202d20636f7069652e7061 67657300000000000000000000000000000000000000000000000000000000000000000000000000 000000360f06c5c03419000000000000000000010002000009200000000000000000000000000000 0009446f63756d656e747300001000080000c45c70cf0000001100080000c5c0260900000001000c 0008a77c0008a76f00006bdf000200414d6163696e746f73682048443a55736572733a7976616e5f 6b6f656e69673a446f63756d656e74733a53616e73207469747265202d20636f7069652e70616765 7300000e0032001800530061006e00730020007400690074007200650020002d00200063006f0070 00690065002e00700061006700650073000f001a000c004d006100630069006e0074006f00730068 0020004800440012003455736572732f7976616e5f6b6f656e69672f446f63756d656e74732f5361 6e73207469747265202d20636f7069652e7061676573001300012f00001500020012ffff0000"/>
<sf:span sf:style="SFWPCharacterStyle-7">
vers autre document
</sf:span>
</sf:link>
<sf:br/>
*)
if removeLinks then
(* supprime les descripteurs de liens *)
set theKey1 to "<sf:link href="
set theKey3 to "<sf:span sf:style="
set theKey4 to "</sf:link>"
set theKey5 to "</sf:span>"
if texte contains theKey1 then
set my liste to my decoupe(texte, theKey1)
repeat with i from 2 to count of my liste
set itm to my decoupe(item i of my liste, theKey4)
set itm1 to item 2 of my decoupe(item 1 of itm, theKey3)
set itm1 to text (1 + (offset of ">" in itm1)) thru -1 of itm1
set itm1 to item 1 of my decoupe(itm1, theKey5)
set itm2 to my recolle(items 2 thru -1 of itm, theKey4)
set item i of my liste to (itm1 & itm2)
end repeat -- i
set texte to my recolle(my liste, "")
end if -- texte contains
(*
This piece of code takes care of a bug in the save as Pages '08 process.
A link to an other document is not completely disabled so the 'disabled' link remains blue.
The link is stored this way:
<sf:p sf:style="paragraph-style-32">
<sf:span sf:style="SFWPCharacterStyle-7">vers autre document</sf:span>
<sf:br/>

when it would be:
<sf:p sf:style="paragraph-style-32">
vers autre document
<sf:br/>
*)
if texte contains theKey3 then
set my liste to my decoupe(texte, theKey3)
repeat with i from 2 to count of my liste
set itm to my decoupe(item i of my liste, theKey5)
set itm1 to item 1 of itm
set itm1 to text (1 + (offset of ">" in itm1)) thru -1 of itm1
set itm2 to my recolle(items 2 thru -1 of itm, theKey5)
set item i of my liste to (itm1 & itm2)
end repeat -- i
set texte to my recolle(my liste, "")
end if -- texte contains
end if -- removeLinks

set lineFeed to ASCII character 10
if texte contains (lineFeed & lineFeed) then set texte to my recolle(my decoupe(texte, lineFeed & lineFeed), lineFeed)
if texte contains (return & return) then set texte to my recolle(my decoupe(texte, return & return), return)

set eof of file theIndex to 0
write texte to file theIndex

my nettoie()
end traiteIndex

--=====

on decoupe(t, d)
local l
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to ""
return l
end decoupe

--=====

on recolle(l, d)
local t
set AppleScript's text item delimiters to d
set t to l as text
set AppleScript's text item delimiters to ""
return t
end recolle

--=====

on nettoie()
set liste to {}
end nettoie

--=====

(* Expands the zip file z in the container d, z and d are pathnames as strings *)
on expandDoc(z, d)
do shell script "unzip " & quoted form of (POSIX path of (z)) & " -d " & quoted form of (POSIX path of (d))
end expandDoc

--=====

on expandIndex(f)
do shell script "gunzip " & quoted form of (POSIX path of (f))
end expandIndex

--=====

on lisIndex_xml(f)
local t
try
set t to ""
set t to (read file f)
end try
return t
end lisIndex_xml

--=====

on compactIndex(nDoc)
local aliasNDoc
set aliasNDoc to nDoc as alias
write leTexte to aliasNDoc starting at 0
do shell script "gzip " & quoted form of POSIX path of aliasNDoc
end compactIndex

--=====
--[/SCRIPT](code}

Yvan KOENIG (from FRANCE samedi 14 mars 2009 20:55:42)

How to remove all hyperlinks at once?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.