Wednesday, November 20, 2019

#1 2019-10-17 02:20:56 pm

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 449

Is there any way to make Spotlight index .applescript files?

I loved it when I got Script Debugger and it came with a spotlight plugin that indexed the contents of my .scpt files, so I could do things like search for all uses of a particular handler across all scripts... or if I couldn't remember which script I'd solved some particular problem in, I could usually find it by search.

We recently moved to git, and since git diff's and merges are pretty useless on .scpt files, we switched all our scripts to .applescript files.

(incidentally, git diff and merge are still pretty useless, due to something about our newline character, we think... working on that one still)

Anyway, now Spotlight no longer indexes our scripts.

It seems like, since they're just plain text files, it would be easy to make them get indexed, since Spotlight already indexes plain text files if they just have the extension ".txt" instead of ".applescript," but I couldn't Google up a way to do that. Seems like I'd have to make a spotlight plugin?

I can always request to Mark that he update his existing plugin to get .applescript too, I was sort of surprised that it doesn't just get them. But I thought I'd ask here before I go requesting new features.

Thanks,

t.spoon


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

#2 2019-10-17 04:51:58 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6036

Re: Is there any way to make Spotlight index .applescript files?

It should be indexing .applescript files — although once you modify the contents elsewhere, the metadata will be out of date, if not deleted. I'll log a bug.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2019-10-17 06:54:11 pm

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 449

Re: Is there any way to make Spotlight index .applescript files?

Thanks.

I did just check again to confirm I'm not going nuts... but I've got a folder with... lots of .applescript files containing lots of code, and if I Spotlight search that folder for "set" it only turns up a couple files that have that string within the file name. Surely every file contains that.

I double-checked my Spotlight preferences to be sure there's not way this folder's excluded under "Privacy." It's not. Also, if it weren't being indexed at all, the file name hits wouldn't turn up.

If it's supposed to be indexing them, it seems like a bug.

I also confirmed that it is still working to index my .scpt files, so it's not like the plugin is just failing on my computer.

- t.spoon


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

#4 2019-11-04 04:42:37 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6036

Re: Is there any way to make Spotlight index .applescript files?

This should be fixed in Script Debugger 7.0.10. But there are a couple of things to be aware of. In particular, the OS decides what order it uses to load importers in the same domain, so if you keep older versions of SD around, you may not notice any difference. And even if you remove them, you may need to force a re-index.

If you really want to keep old versions around, you can force the latest version by copying the importer from SD's bundle to ~/Library/Spotlight. Importers found there have preference over those in apps.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#5 2019-11-08 10:33:55 am

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 449

Re: Is there any way to make Spotlight index .applescript files?

Confirmed working. This is great, thanks Shane!


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

#6 2019-11-08 05:12:41 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6036

Re: Is there any way to make Spotlight index .applescript files?

I'm curious: did you have to force a rebuild, or did it happen automatically?


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#7 2019-11-08 07:27:30 pm

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 449

Re: Is there any way to make Spotlight index .applescript files?

I had to force. I added just my scripts folder to the "Privacy" pane in the Spotlight System Preferences, then took it back off, and it immediately indexed just my scripts folder.

But I had updated Script Debugger a couple of days ago (whenever I got the prompt) and tried a few searches first, and they didn't work. I don't know if it would have gotten re-indexed automatically eventually or not.

Thanks again,

Tom.


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

#8 2019-11-13 10:50:50 am

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 449

Re: Is there any way to make Spotlight index .applescript files?

Well, it's working partially.

To test I'd just been going to my main script folder and running a spotlight search in-folder for something widely used, like "set," or "text item."

I was getting no results from .applescript files. Then after the last Script Debugger update, and adding and removing my scripts folder in the Spotlight "privacy" pane, the same search in the same folder returned lots of results.

But yesterday, I had a library open, and a script that called a function in the library, and I needed to add a parameter to the library function. So I had to find all scripts calling it to update the calls.

So I thought "great! Spotlight is working again!"

I did the spotlight search for the function name inside my script folder... and it turned up some scripts, but I noticed it did NOT turn up the script I was working on! Which obviously had the call, and had for quite some time. So I tried several more searches for terms that I knew existed in several scripts, and it was hit or miss. I am definitely getting some hits for full text search of .applescript files, but can also find scripts that definitely should be turning up - that contain the searched term and are located in the searched directory - that do not turn up.

No idea if that can have anything to do with the plugin, or if it's an Apple flaw in Spotlight. I'll try forcing it to reindex everything and see if that helps... but adding and removing the file from the "Privacy" pane definitely forced at least a partial re-indexing, so that doesn't seem likely.

I don't have any prior versions of Script Debugger installed, just the latest.

Another developer told me that he uses Sublime Text to do full text search of his Applescripts, so I'll give that a shot.

Thanks,

tspoon.


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

#9 2019-11-13 12:29:43 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3635

Re: Is there any way to make Spotlight index .applescript files?

I am accustomed to store my scripts as .applescript files stored in subfolders of a dedicated folder so, when I need to search for a string in them I use the free Easyfind which return very quickly the list of files containing the searched string.
The only feature which is missing - from my point of view - is the fact that we can't copy the returned list. When I copy it, the clipboard contain icons but say that it doesn't contain text datas.

I use GUI scripting to extract the useful infos:

Applescript:

set targetFile to (path to desktop as text) & "filesFound.txt"
tell application "System Events" to tell process "EasyFind"
   set frontmost to true
   tell window 1
       --class of UI elements --> {button, button, button, scroll area, button, checkbox, checkbox, checkbox, radio group, radio group, checkbox, checkbox, static text, static text, static text, static text, text field, menu button, static text, list, toolbar, static text}
       select row 1 of table 1 of scroll area 1 # reveal the list of path components
       
       set folderName to name of menu button 1 --> "des scripts"
       --class of UI elements
       set theItems to value of attribute "AXChildren" of list 1
       set pathComponents to {}
       repeat with i from 1 to 1000 # a fake value
           set aComponent to value of item i of theItems
           set end of pathComponents to aComponent
           if aComponent = folderName then exit repeat
       end repeat
       set begOfPath to "/Users/" & my recolle(pathComponents, "/")
       
       # Here, begOfPath is: "/Users/my user name/Documents/mon bureau/des scripts"
       
       my writeto(targetFile, begOfPath & linefeed, «class utf8», false) # create the report file
       
       tell scroll area 1
           --class of UI elements --> {table, scroll bar}
           tell table 1
               --class of UI elements --> {row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, column, column, column, column, column, column, group}
               set nbr to count rows
               set theInfos to {}
               repeat with i from 1 to nbr
                   tell row i
                       --class of UI elements --> {static text, static text, static text, text field, text field, static text}
                       set fName to value of static text 1
                       if fName ends with ".applescript" then my writeto(targetFile, fName & tab & value of static text -1 & linefeed, «class utf8», true)
                   end tell
               end repeat
           end tell
       end tell
       
   end tell
end tell

#=====

on recolle(l, d)
   local oTIDs, t
   set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, 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 «class furl»
       set openFile to open for access targetFile with write permission
       if not apendData 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

#=====

It's slow but it return a file containing the list of the filenames and the partial path of these files in the target folder whose path is stored ain the first line of the document.

Maybe it may help others.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 13 novembre 2019  19:29:06

Offline

 

#10 2019-11-13 12:39:35 pm

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 449

Re: Is there any way to make Spotlight index .applescript files?

Thanks Yvan, I'll give Easy Find a try.

Usually, I don't need a log of what's found.

If you do need a log, you might try my Applescript Find/Replace script here:

https://www.macscripter.net/viewtopic.php?id=47109

It is also slow, but it generates a nice spreadsheet showing the text of the line(s) in which the searched term was found, as well as the file path to the file.

Note that Nigel said he encountered an issue with the "replace" functionality in .scpt files. In my testing it had worked, but I'll investigate further when I have time.

Last edited by t.spoon (2019-11-13 12:59:01 pm)


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

#11 2019-11-13 04:13:34 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6036

Re: Is there any way to make Spotlight index .applescript files?

t.spoon wrote:

No idea if that can have anything to do with the plugin, or if it's an Apple flaw in Spotlight.



The plug-in just passes on the whole contents of a document to Spotlight. It's a black box from then on.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#12 2019-11-14 05:06:25 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3635

Re: Is there any way to make Spotlight index .applescript files?

Oops, driving EasyFind with GUIscripting was a bad idea.

Below is a script doing more job in a hurry.

Applescript:

----------------------------------------------------------------
use AppleScript version "2.5"
use framework "Foundation"
use script "FileManagerLib" version "2.2.2"
use scripting additions
----------------------------------------------------------------
script o
   property theURLs : {}
   property thePaths : {}
end script

my germaine()

on germaine()
   set targetDir to (path to documents folder as text) & "mon bureau:des scripts:" # Edit to fit your needs
   set startTime to time of (current date)
   
   my listFolder:(POSIX path of targetDir)
   
   set targetFile to (path to desktop as text) & "applescripts.txt"
   my writeto(targetFile, my concatList:(o's thePaths) usingString:linefeed, «class utf8», false)
   set executeTime to (time of (current date)) - startTime --> 8
end germaine

on listFolder:posixPath
   set theKey to "localized" # Edit to fit your needs
   # You may also define a replacement string
   
   set o's theURLs to objects of posixPath result type urls array with searching subfolders without include folders and include invisible items
   if o's theURLs is {} then error "Le dossier “" & posixPath & "” est vide."
   
   set o's thePaths to {} # useful if we run the script several times in a row
   repeat with aURL in o's theURLs
       set itsPath to (aURL's valueForKey:"path") as text
       
       
       if itsPath ends with ".applescript" then
           set theName to (aURL's lastPathComponent()) as text
           
           set itsText to read ((POSIX file itsPath) as «class furl»)
           if itsText contains theKey then
               set end of o's thePaths to itsPath
               
               # you may trigger the handler remplace2 if you want to apply the replacement
               # and write the modified text.
               
               repeat with aLine in paragraphs of itsText
                   if aLine contains theKey then set end of o's thePaths to (aLine as text)
               end repeat
           end if
       end if # itsPath ends with ".applescript"
   end repeat
end listFolder:

#=====

on concatList:theList usingString:d1
   set anArray to current application's NSArray's arrayWithArray:theList
   return (anArray's componentsJoinedByString:d1) as string
end concatList:usingString:

#=====

on remplace2(t, d1, d2)
   set aString to (current application's NSString's stringWithString:t)
   -- Case insensitively replace any instances of d1 by d2
   set aString to aString's stringByReplacingOccurrencesOfString:d1 withString:d2 options:(current application's NSCaseInsensitiveSearch) range:{0, aString's |length|()}
   return aString as string
end remplace2

#=====
(*
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 «class furl»
       set openFile to open for access targetFile with write permission
       if not apendData 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 targetFile
       end try
       return false
   end try
end writeto

#=====

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 14 novembre 2019  12:00:08

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)