Welcome to NeoOffice developer notes and announcements
NeoOffice
Developer notes and announcements
 
 

Download or installation problems? Try these steps
Problems after upgrading to NeoOffice 2017? Try these steps


Support
· NeoOffice Support
· NeoWiki


Announcements
· Twitter @NeoOffice


Downloads
· Download NeoOffice


RSS Feeds
· Announcements Only
· All Posts


  
NeoOffice :: View topic - This AppleScript searches content of Writer and Calc Files!
This AppleScript searches content of Writer and Calc Files!
 
Post new topic   Reply to topic    NeoOffice Forum Index -> NeoOffice Releases
View previous topic :: View next topic  
Author Message
GibHenry
Councilperson


Joined: Jun 20, 2003
Posts: 104
Location: Birmingham, Alabama; and Amelia (Terni), Italy

PostPosted: Tue Mar 15, 2005 8:30 am    Post subject: This AppleScript searches content of Writer and Calc Files! Reply with quote

(*
Courtesy of an unnamed angel on the Apple forums ("biovizier" of Ontario), here is an AppleScript which will search a specified folder and its subfolders for any occurrence of a specified string inside any .sxw or .sxc file.

When I asked how to give him credit, he modestly replied, "The script itself still has a lot of limitations, like that fact that it will choke on various forms of punctuation in the search string, or the way it scans the entire contents of the zip archive, not just the actual 'text', both of which could lead to unexpected results. It's much more important that that info gets passed on..."

Five lines of code have been split for posting. If the script doesn't compile, try deleting the "¬" characters and joining the two lines that each "¬" separates. For best results, set your list view options (cmd-J) to display comments. Save the script in either "/Library/Scripts" or your user "~/Library/Scripts" folder (make one if it doesn't exist), then you can access it from your "Scripts" menu. The "Scripts" menu can be enabled by launching "/Application" > "AppleScript" > "Install Script Menu".
*)

---
property qt : ASCII character 34
set typext to " -regex " & qt & ".*/*sx[cw]" & qt
set searchinfo to (display dialog "Enter search string and choose file type" default answer ¬
"" buttons {"Writer", "Calc", "Writer & Calc"} default button 3)
set thestring to text returned of searchinfo
set thetype to button returned of searchinfo
if thetype is "Writer" then
set typext to " -name " & qt & "*.sxw" & qt
else if thetype is "Calc" then
set typext to " -name " & qt & "*.sxc" & qt
end if
set theFolder to quoted form of POSIX path of (choose folder)
set part1 to "for i in `find " & theFolder & typext & " | sed 's/ /:/g'`;"
set part2 to "do unzip -p " & qt & "`echo " & qt & "$i" & qt & " | tr ':' ' '`" & qt ¬
& " | grep -i " & qt & thestring & qt & " 1>/dev/null;"
set part3 to "if [ $? = 0 ]; then founds=" & qt & ¬
"$founds`echo $i | tr ':' " & qt & " " & qt & "`:" & qt & ";"
set part4 to "fi; done; echo " & qt & "$founds" & qt & " | sed 's@//@/@g'"
set founds to (do shell script part1 & part2 & part3 & part4)
if founds is "" then
display dialog "The string " & qt & thestring & qt & ¬
" was not found" buttons {"Cancel"} default button 1
end if
set my text item delimiters to ":"
set thelist to text items of founds
if (count of thelist) is 2 then
try
tell application "Finder"
activate
reveal (POSIX file (item 1 of thelist) as alias)
end tell
end try
return
end if
set thelistPlus to thelist
set the last item of thelistPlus to "Alias Selected (Default 'All')"
set chosen to (choose from list thelistPlus with prompt ¬
"Choose files to 'reveal'" with multiple selections allowed)
if chosen contains "Alias Selected (Default 'All')" then
if (count of chosen) is 1 then
set chosen to thelist
end if
set cd to (current date)
set resultsf to "Search " & (word 1 of thestring) & "..." & day of cd & time of cd
tell application "Finder"
set resultsfl to (make new folder at desktop with properties {name:resultsf})
try
repeat with afound in chosen
set thisalias to (make alias file to POSIX file afound at resultsfl)
set comment of thisalias to (do shell script "dirname " & qt & afound & qt)
end repeat
end try
open resultsfl
set properties of window 1 to {toolbar visible:(false), current view:(list view)}
set zoomed of window 1 to true
activate
end tell
else
set revealist to {}
try
repeat with eachosen in chosen
set chosenpath to POSIX file eachosen
set revealist to revealist & chosenpath
end repeat
tell application "Finder"
activate
set selecton to items in revealist
reveal revealist
end tell
end try
end if
---

_________________
Gib Henry
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    NeoOffice Forum Index -> NeoOffice Releases All times are GMT - 7 Hours
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Powered by phpBB © 2001, 2005 phpBB Group

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest © Planamesa Inc.
NeoOffice is a registered trademark of Planamesa Inc. and may not be used without permission.
PHP-Nuke Copyright © 2005 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.03 Seconds