i’ve searched the forum but can’t find a script like this. (by the way, I’m a newbie at scripting!)
I have a lot of text from transcribers software which has a time tag at the start of every line.
what I’d like to do is create a script that I can run in Pages that will find the #, then count it and the 12 characters after it, and delete them.
this would save me a LOT of time…
example below: #00:03:52-8# it enables us to use a language which facilitates high quality #00:06:28-1# the best thing said in that tape
thanks!
Joe Lafferty, Dundee Scotland
Model: MacBook Pro
AppleScript: latest? Lion
Browser: Safari 534.48.3
Operating System: Mac OS X (10.7)
tell application "Pages"
tell document 1
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "# "}
repeat with i from 1 to (count paragraphs)
set textItems to text items of (get paragraph i)
if (count textItems) > 1 then
set paragraph i to (items 2 thru -1 of textItems) as text
end if
end repeat
set AppleScript's text item delimiters to ASTID
end tell
end tell
(*
Yvan KOENIG (VALLAURIS, France)
2011/11/30
*)
tell application "Pages" to tell document 1
set body_text to body text
end tell
set tempFile to (path to temporary items from local domain as text) & "wasInPages.txt"
my writeTo(tempFile, body_text, text, false)
set en_liste to paragraphs of (read file tempFile)
repeat with i from 1 to count of en_liste
set une_ligne to item i of en_liste
if une_ligne starts with "#" then set item i of en_liste to text 14 thru -1 of une_ligne
end repeat
tell application "Pages" to tell document 1
set body text to my recolle(en_liste, return)
end tell
--=====
on recolle(l, d)
local oTIDs, t
set oTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to d
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end recolle
--=====
(*
Handler borrowed to Regulus6633 - http://macscripter.net/viewtopic.php?id=36861
*)
on writeTo(targetFile, theData, dataType, apendData)
-- targetFile is the path to the file you want to write
-- theData is the data you want in the file.
-- dataType is the data type of theData and it can be text, list, record etc.
-- apendData is true to append theData to the end of the current contents of the file or false to overwrite it
try
set targetFile to targetFile as text
set openFile to open for access file targetFile with write permission
if apendData is false then set eof of openFile to 0
write theData to openFile starting at eof as dataType
close access openFile
return true
on error
try
close access file targetFile
end try
return false
end try
end writeTo
--=====
I use an ugly code to split the text into paragraphs because, when I pasted the text of your message in a Pages document, it was treated as a single paragraph.
Yvan KOENIG (VALLAURIS, France) mercredi 30 janvier 2011 13:02:12
I copied the original message, pasted it in a Blank Pages document.
When my first script grabbed the body text, count of paragraphs returned 1.
tell application "Pages" to tell document 1
set body_text to body text
log (count of paragraphs)
end tell
log (count of paragraphs of body_text)
log "4th character : " & (ASCII number of character 4 of body_text)
log "return : " & (ASCII number of return)
set les_paragraphes to my decoupe(body_text, return)
log (count of les_paragraphes)
--=====
on decoupe(t, d)
local oTIDs, l
set oTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to oTIDs
return l
end decoupe
--=====
The log report was :
tell application “Pages”
get body text of document 1
→ “Hi,¨¨i’ve searched the forum but can’t find a script like this. (by the way, I’m a newbie at scripting!)¨¨I have a lot of text from transcribers software which has a time tag at the start of every line.¨what I’d like to do is create a script that I can run in Pages that will find the #, then count it and the 12 characters after it, and delete them.¨this would save me a LOT of time…¨¨example below:¨#00:03:52-8# it enables us to use a language which facilitates high quality ¨#00:06:28-1# the best thing said in that tape¨¨thanks!¨¨Joe Lafferty, Dundee Scotland¨¨Model: MacBook Pro¨AppleScript: latest? Lion¨Browser: Safari 534.48.3¨Operating System: Mac OS X (10.7)”
count every paragraph of document 1
→ 1
(1)
end tell
(1)
tell current application
ASCII number “¨”
→ 13
(character 4 : 13)
ASCII number "
"
→ 13
(return : 13)
(1)
end tell
body_text contain at least one carriage return (4th character) but I can’t split it into paragraphs.
In an other attempt, I copied from the message,
ran the huge script :
set the clipboard to the clipboard as text
then pasted in Pages.
This time I got the paragraphs.
I’m really puzzled.
Yvan KOENIG (VALLAURIS, France) mercredi 30 janvier 2011 17:38:11
the simple elegant script worked a treat! thanks!!
you’ve saved me a lot of time and made me a very happy camper!!
excuse me for the newbie question, but is there an easy way to run this from Pages other than opening the script every time and pressing run?
by the way, I’m coming to St. Gallen sometime in March as I’m delivering part of the Diploma in Sustainable Business.
first time in your country and really looking forward to it.
regards,
Joe Lafferty
Dundee Scotland
Model: MacBook Pro
AppleScript: latest? Lion
Browser: Safari 534.48.3
Operating System: Mac OS X (10.7)
I tried saving to ~/library/scripts, and the script menu was enabled, however no success - i’ve searched a while on the internet and, i know this may be really obvious, but I’m stumped!
my pages services menu only has a few items on it.
I have screen shots of what i see but can’t seem to upload them.
Joe
Model: MacBook Pro
AppleScript: latest? Lion
Browser: Safari 534.48.3
Operating System: Mac OS X (10.7)
¢ Launch Automator
¢ Choose template Service
¢ Choose no input from popup menu Service receives
¢ Choose Pages from popup menu in
¢ Drag a Run AppleScript action into the action area
¢ Replace (* Your script goes here *) with the script code
¢ Save it
Then you can run the script from the services menu
Thanks Stefan!
i also found the script folder in my menu bar! i’ve been using a mac for 4 yrs now, and am pretty proficient, but clearly there are still big holes in my knowledge!!
I’ll stick with the menu bar as that’s more straightforward.
thanks for your time and tips, very helpful.
regards,
Joe
A simple search in Google, Bing. for FastScripts will let you discover a tool allowing us to link shortcuts to scripts.
I’m using the free version (limited to ten shortcuts).
I adopted a standard structure for the linked shortcuts cmd + alt + ctrl + character and it’s really efficient.
For instance I will insert my signature with cmd + alt + ctrl + y
Yvan KOENIG (VALLAURIS, France) jeudi 1 janvier 2011 14:15:24