Help with Searching .pdf's

I have been trying to make an Automator that will search .pdf's for long list of words then display the words found.


Firstly - can anyone help with Automator to do this? If not, I thought I could put the long list of words (they never change) in a text document and when I want, copy and paste them into the preview .pdf search bar. But this has not worked well - I dont know if there need to be " " for each term, use a comma between words or " | " or nothing at all??


Thank you

MacBook Pro 16″, macOS 12.5

Posted on Aug 18, 2022 11:23 AM

Reply
Question marked as Top-ranking reply

Posted on Aug 25, 2022 6:01 PM

It would appear the the copy/paste to the hosting community changed the double quote to its HTML equivalent which is " .


Try copy/pasting this code into an existing AppleScript-Cocoa app template per the instructions:


(*
	pdfsearch.applescript
	
	Given a text file containing single, compound, or quoted word strings, and without any empty lines,
	use that as a wordlist to find all occurrences of those words, and the pages found,
	in a given PDF document.
	
	Produce a text report of the words that match, and the found page numbers. That text
	report is written to the original PDF Document location with a "_matched.txt" suffix.
	
	Code does not work reliably in Automator's Run AppleScript workflow. On M1/M2 Macs, won't work
	as a saved AppleScript application. In Script Editor, use the following to build it:
	  1) File menu > New From Template > Cocoa-AppleScript Applet.
	  2) Paste the following AppleScript/Objective-C into the preceding template
	  3) Click the hammer icon to compile the code
	  4) Option-key + File menu > Save As…
	        a) File format: Script Bundle
		 b) set filename to pdfsearch.scptd
		 c) no options set
		 d) Save
	  5) Double-click pdfsearch.scpt to run it
	
	Reference: https://discussions.apple.com/thread/254122468
	Tested: macOS 11.6.8, 12.5.1
	Version: 1.1
	Author: VikingOSX, 2022-08-25, Apple Support Communities, no warranties expressed or implied.
*)

use framework "Foundation"
use framework "PDFKit"
use AppleScript version "2.4" -- macOS Yosemite or later
use scripting additions

property PDFDocument : a reference to current application's PDFDocument
property NSString : a reference to current application's NSString
property NSUTF8StringEncoding : a reference to current application's NSUTF8StringEncoding
property NSURL : a reference to current application's NSURL
property NSArray : a reference to current application's NSArray
property NSMutableOrderedSet : a reference to current application's NSMutableOrderedSet
property NSMutableString : a reference to current application's NSMutableString
property NSMutableArray : a reference to current application's NSMutableArray
property NSLiteralSearch : a reference to current application's NSLiteralSearch
property NSCaseInsensitiveSearch : a reference to current application's NSCaseInsensitiveSearch

property WORDFILE : "~/Desktop/search_words.txt"

-- prompt for one or more PDFs. This script does not perform Optical Character Recognition of scans.
set PDFs to (choose file of type {"com.adobe.pdf"} with multiple selections allowed)

-- make the tilde path as absolute path
set xwordfile to (NSString's stringWithString:WORDFILE)'s stringByStandardizingPath()

-- get the WORDFILE into an array
set searchFile to NSString's alloc()'s initWithContentsOfFile:xwordfile encoding:NSUTF8StringEncoding |error|:0
set searchWords to (NSArray's arrayWithArray:(searchFile's componentsSeparatedByString:linefeed))'s mutableCopy()

set outfilename to NSMutableString's alloc()'s init()
-- "exact case matches" from the WORDFILE can omit the addition of the NSCaseInsensitiveSearch
set findOptions to (NSLiteralSearch as integer) + (NSCaseInsensitiveSearch as integer)

-- these Set data structures automatically purge duplicates and order ascending.
-- search word matches will appear alphabetical and page numbers ascending
set nameset to NSMutableOrderedSet's alloc()'s init()
set pageset to NSMutableOrderedSet's alloc()'s init()

repeat with apdf in PDFs
	-- add the following suffix to the original PDF path and name.
	(outfilename's setString:((NSString's stringWithString:(POSIX path of apdf))'s stringByDeletingPathExtension()))
	(outfilename's appendString:"_matched.txt")
	
	set pdf to (PDFDocument's alloc()'s initWithURL:(NSURL's fileURLWithPath:(POSIX path of apdf)))
	
	repeat with aword in searchWords
		set found to (pdf's findString:aword withOptions:findOptions)
		if not (count of (found as list)) = 0 then
			repeat with selection in found
				(nameset's addObject:((selection's |string|()) as text))
				repeat with apage in selection's pages()
					(pageset's addObject:(apage's label()))
				end repeat
			end repeat
			
			set aname to (nameset's allObjects()'s firstObject()) as text
			set pageStr to ((pageset's allObjects()'s componentsJoinedByString:", ") as text)'s quoted form
			
			if not (aname contains missing value) = true then
				set args to (outfilename as text)'s quoted form & space & aname's quoted form & space & pageStr
				my format_and_write(args)
			end if
			
			# reset these orderedSets for next word search results
			nameset's removeAllObjects()
			pageset's removeAllObjects()
		end if
	end repeat
	
end repeat
return

on format_and_write(args)
	-- allow for left-justified 20 character word matches and 40 character page sequences
	-- 1 = outfilename 2 = aname 3 = pageStr
	return (do shell script "/bin/zsh -s <<'EOF' - " & args & "
#!/bin/zsh
printf '%-20s%-40s\\n' $2 $3 >> $1
EOF")
end format_and_write


69 replies
Question marked as Top-ranking reply

Aug 25, 2022 6:01 PM in response to mrchntmarine

It would appear the the copy/paste to the hosting community changed the double quote to its HTML equivalent which is &#34; .


Try copy/pasting this code into an existing AppleScript-Cocoa app template per the instructions:


(*
	pdfsearch.applescript
	
	Given a text file containing single, compound, or quoted word strings, and without any empty lines,
	use that as a wordlist to find all occurrences of those words, and the pages found,
	in a given PDF document.
	
	Produce a text report of the words that match, and the found page numbers. That text
	report is written to the original PDF Document location with a "_matched.txt" suffix.
	
	Code does not work reliably in Automator's Run AppleScript workflow. On M1/M2 Macs, won't work
	as a saved AppleScript application. In Script Editor, use the following to build it:
	  1) File menu > New From Template > Cocoa-AppleScript Applet.
	  2) Paste the following AppleScript/Objective-C into the preceding template
	  3) Click the hammer icon to compile the code
	  4) Option-key + File menu > Save As…
	        a) File format: Script Bundle
		 b) set filename to pdfsearch.scptd
		 c) no options set
		 d) Save
	  5) Double-click pdfsearch.scpt to run it
	
	Reference: https://discussions.apple.com/thread/254122468
	Tested: macOS 11.6.8, 12.5.1
	Version: 1.1
	Author: VikingOSX, 2022-08-25, Apple Support Communities, no warranties expressed or implied.
*)

use framework "Foundation"
use framework "PDFKit"
use AppleScript version "2.4" -- macOS Yosemite or later
use scripting additions

property PDFDocument : a reference to current application's PDFDocument
property NSString : a reference to current application's NSString
property NSUTF8StringEncoding : a reference to current application's NSUTF8StringEncoding
property NSURL : a reference to current application's NSURL
property NSArray : a reference to current application's NSArray
property NSMutableOrderedSet : a reference to current application's NSMutableOrderedSet
property NSMutableString : a reference to current application's NSMutableString
property NSMutableArray : a reference to current application's NSMutableArray
property NSLiteralSearch : a reference to current application's NSLiteralSearch
property NSCaseInsensitiveSearch : a reference to current application's NSCaseInsensitiveSearch

property WORDFILE : "~/Desktop/search_words.txt"

-- prompt for one or more PDFs. This script does not perform Optical Character Recognition of scans.
set PDFs to (choose file of type {"com.adobe.pdf"} with multiple selections allowed)

-- make the tilde path as absolute path
set xwordfile to (NSString's stringWithString:WORDFILE)'s stringByStandardizingPath()

-- get the WORDFILE into an array
set searchFile to NSString's alloc()'s initWithContentsOfFile:xwordfile encoding:NSUTF8StringEncoding |error|:0
set searchWords to (NSArray's arrayWithArray:(searchFile's componentsSeparatedByString:linefeed))'s mutableCopy()

set outfilename to NSMutableString's alloc()'s init()
-- "exact case matches" from the WORDFILE can omit the addition of the NSCaseInsensitiveSearch
set findOptions to (NSLiteralSearch as integer) + (NSCaseInsensitiveSearch as integer)

-- these Set data structures automatically purge duplicates and order ascending.
-- search word matches will appear alphabetical and page numbers ascending
set nameset to NSMutableOrderedSet's alloc()'s init()
set pageset to NSMutableOrderedSet's alloc()'s init()

repeat with apdf in PDFs
	-- add the following suffix to the original PDF path and name.
	(outfilename's setString:((NSString's stringWithString:(POSIX path of apdf))'s stringByDeletingPathExtension()))
	(outfilename's appendString:"_matched.txt")
	
	set pdf to (PDFDocument's alloc()'s initWithURL:(NSURL's fileURLWithPath:(POSIX path of apdf)))
	
	repeat with aword in searchWords
		set found to (pdf's findString:aword withOptions:findOptions)
		if not (count of (found as list)) = 0 then
			repeat with selection in found
				(nameset's addObject:((selection's |string|()) as text))
				repeat with apage in selection's pages()
					(pageset's addObject:(apage's label()))
				end repeat
			end repeat
			
			set aname to (nameset's allObjects()'s firstObject()) as text
			set pageStr to ((pageset's allObjects()'s componentsJoinedByString:", ") as text)'s quoted form
			
			if not (aname contains missing value) = true then
				set args to (outfilename as text)'s quoted form & space & aname's quoted form & space & pageStr
				my format_and_write(args)
			end if
			
			# reset these orderedSets for next word search results
			nameset's removeAllObjects()
			pageset's removeAllObjects()
		end if
	end repeat
	
end repeat
return

on format_and_write(args)
	-- allow for left-justified 20 character word matches and 40 character page sequences
	-- 1 = outfilename 2 = aname 3 = pageStr
	return (do shell script "/bin/zsh -s <<'EOF' - " & args & "
#!/bin/zsh
printf '%-20s%-40s\\n' $2 $3 >> $1
EOF")
end format_and_write


Aug 21, 2022 11:56 AM in response to mrchntmarine

Ok. Done testing on macOS 11.6.8 (M1) and macOS 12.5.1 (M1, Intel) and works the same across these platforms as a Quick Action. Here's how you build the Automator workflow in the following order:


  1. Library: Files and Folders : Get Specified Finder Items
    1. You add your text file containing the search words here.
  2. Library: Files and Folders: Filter Finder Items (You can see how this is implemented in the workflow screen capture).
  3. Library: Utilities: Run AppleScript
    1. Once you have drag and dropped this into the workflow, select and remove all content from it, and you will replace that with the following code.


Code:


use framework "Foundation"
use framework "PDFKit"
use AppleScript version "2.4" -- Yosemite or later
use scripting additions

property PDFDocument : a reference to current application's PDFDocument
property NSArray : a reference to current application's NSArray
property NSCharacterSet : a reference to current application's NSCharacterSet
property NSURL : a reference to current application's NSURL

property NSString : a reference to current application's NSString
property NSPredicate : a reference to current application's NSPredicate
property NSUTF8StringEncoding : a reference to current application's NSUTF8StringEncoding

on run {input, parameters}
	
	set searchFile to POSIX path of (item 1 of input) as text
	# force each of the PDFs to be a POSIX path instead of the Finder's HFS format
	set pdfs to (NSArray's arrayWithArray:(rest of input as list))'s allObjects()'s valueForKey:"path"
	
	# what we use to clean up extraneous characters in the pdf text
	set alnum to (NSCharacterSet's alphanumericCharacterSet)'s mutableCopy()
	set nopunct to NSCharacterSet's punctuationCharacterSet
	alnum's formUnionWithCharacterSet:nopunct
	alnum's invertedSet()
	
	# get the search words into their array
	set searchFile to (NSString's alloc()'s initWithContentsOfFile:searchFile encoding:NSUTF8StringEncoding |error|:0)
	set searchWords to NSArray's arrayWithArray:(searchFile's componentsSeparatedByString:linefeed)
	
	repeat with aPDF in pdfs
		# make specific output text file for each PDF
		set OUTFILE to (NSString's stringWithString:aPDF)'s stringByDeletingPathExtension()'s mutableCopy()
		(OUTFILE's appendString:"_matched.txt")
		set pdfName to aPDF's lastPathComponent() as text
		
		# get all of the words in the current PDF document into a cleaned up array
		set pdf to (PDFDocument's alloc()'s initWithURL:(NSURL's fileURLWithPath:aPDF))
		set pdfText to (pdf's selectionForEntireDocument())'s |string|() as text
		set mytext to ((NSString's stringWithString:(my split_words(pdfText)))'s stringByTrimmingCharactersInSet:alnum)
		set pdfWords to (mytext's componentsSeparatedByString:linefeed)'s mutableCopy()
		
		# match words from searchFile to the PDF word array
		set pred to (NSPredicate's predicateWithFormat:"SELF IN[c] %@" argumentArray:pdfWords)
		set matchedWords to (searchWords's filteredArrayUsingPredicate:pred)'s mutableCopy()
		
		if not ((count of matchedWords) = 0) is true then
			set outStr to (matchedWords's componentsJoinedByString:linefeed)
			(outStr's writeToFile:OUTFILE atomically:true)
		else
			display dialog "No words matched those in the current PDF: " & pdfName & return & "Skipping to next PDF it available." with title "Processing Notice" giving up after 5
			log "skipping"
		end if
		pdfWords's removeAllObjects()
		matchedWords's removeAllObjects()
		set pdfText to ""
		set mytext to ""
	end repeat
	return
end run

on split_words(astr)
	return (do shell script "/bin/zsh -s <<'EOF' - " & astr's quoted form & "
#!/bin/zsh
setopt shwordsplit
# clobber these characters while splitting out words
typeset -a words=( ${(f)${1}//[.,;:!?]} )
print -l ${words}
EOF")
end split_words


Save your Quick Action, I called my Match PDF Words. It will automatically be activated and present in the Finder's Quick Actions sub-menu.


Here is the finished Quick Action workflow:


Aug 24, 2022 2:14 PM in response to mrchntmarine

So here is an update. I have been testing with single words for matches in the test PDF, and I just tested with two-word strings and they matched the PDF content. Answers that question.


Getting the page numbers is one line of code once I have a found object.


The bad news. I cannot get the Automator Quick Action to produce the nicely formatted output that the Script Editor and the identical AppleScript code achieves outside of Automator. No use beating that dog further as the AppleScript runtimes are different in Script Editor and Automator's Run AppleScript action. Wouldn't have had the disparity with higher level languages such as Python or Ruby, but Apple has other plans for anything competing with Swift.


The good news. I can provide you an AppleScript that uses your fixed-name word file to search the PDF, and a prompt for one or multiple PDFs in that AppleScript. Still generates one formatted text file per PDF. You double-click the AppleScript item on your Desktop and away you go. I am done for today. Automator has wore me out. If the AppleScript approach appeals to you, I can deliver that tomorrow.

Aug 25, 2022 5:40 AM in response to mrchntmarine

I have finally settled on an AppleScript-Cocoa applet format that has nothing to do with Automator, but does allow you to use a fixed name text file containing your search words, and it will prompt you for one or more PDFs to search with those words. Here is the result of running this solution on a nineteen-page PDF looking for eleven search words, two of which are not contained in it:



You can use compound names as you require that for ship names. If it would help to have the matching search words in alphabetical order, you can sort the search word file in the Terminal, where the following naming convention is entirely up to you:


sort -d orig_search_words.txt > sorted_search_words.txt


The comments in the header of the AppleScript-Objective-C code instruct on how to create the script bundle that you save to your Desktop, and interactively run with a double-click. The only prompt allows you to choose one or more PDFs for processing. The "_matched.txt" text files (such as the above example) simply borrow the path and filename of each PDF.


Code (click to expand and then copy/paste into the Script Editor per the instructions in the code comments)



Sep 14, 2022 9:47 AM in response to mrchntmarine

Here is the final, more efficient version of the code. It matches all of your search words to each page in one line of code and takes those matching, non-substring words as keys in a dictionary, where it adds matching page numbers as list values. From a user perspective, it works just like the previous version, just much quicker, and uses the newer print facility to wrap the page numbers column.


You use the Cocoa-AppleScript applet template from the Script Editor's File menu > New from Template — just as before, where you copy/paste the following content into it and save as a Script Bundle (scptd). Double-click to be prompted for input PDFs.


I don't trust the Additional Text tool in this toolbar to not munge some characters in the script so I am posting the script in two parts (to avoid the site's 5000 character limit) that you simply append to one another in the Script Editor before the final save.


Part 1:


(*
	pdfsearch_finalx.applescript
	
	One provides a one-per-line list of search words in a text file that
    this script knows where to locate (e.g. WORDFILE). It will prompt for
    one or more (unscanned) PDFs and output separate text files with the PDF
    name and _matched.txt that reflect the search word, and columns of page
    numbers where the search word was found in the individual PDF document.
	
	Reference: https://discussions.apple.com/thread/254122468
	Tested: macOS 11.7, 12.6
	VikingOSX, 2022-09-14, Apple Support Chttps://discussions.apple.com/thread/254122468
*)
use framework "Foundation"
use framework "AppKit"
use framework "PDFKit"
use AppleScript version "2.4" -- macOS Yosemite or later
use scripting additions

property PDFDocument : a reference to current application's PDFDocument
property NSString : a reference to current application's NSString
property NSURL : a reference to current application's NSURL
property NSArray : a reference to current application's NSArray
property NSMutableArray : a reference to current application's NSMutableArray
property NSSet : a reference to current application's NSSet
property NSDictionary : a reference to current application's NSMutableDictionary
property NSUTF8StringEncoding : a reference to current application's NSUTF8StringEncoding

property WORDFILE : "~/Desktop/search_words.txt"

-- make the tilde path as absolute path
set xwordfile to (NSString's stringWithString:WORDFILE)'s stringByStandardizingPath()
-- get the WORDFILE into an array
set searchFile to NSString's alloc()'s initWithContentsOfFile:xwordfile encoding:NSUTF8StringEncoding |error|:0
set searchWords to (NSArray's arrayWithArray:(searchFile's componentsSeparatedByString:linefeed))

set searchSet to (NSSet's setWithArray:searchWords)'s mutableCopy()
set pageSet to NSSet's |set|()'s mutableCopy()
set muDict to NSDictionary's alloc()'s init()'s mutableCopy()

-- prompt for one or more PDFs. This script does not perform Optical Character Recognition of scans.
set PDFs to (choose file of type {"com.adobe.pdf"} with multiple selections allowed)

repeat with apdf in PDFs
	-- prepare the text output filename
	set outfilename to NSString's alloc()'s init()'s mutableCopy()
	-- add the following suffix to the original PDF path and name.
	set xpdf to POSIX path of apdf
	(outfilename's setString:((NSString's stringWithString:xpdf)'s stringByDeletingPathExtension()))
	(outfilename's appendString:"_matched.txt")
	
	set pdf to (PDFDocument's alloc()'s initWithURL:(NSURL's fileURLWithPath:xpdf))
	set pageCnt to pdf's pageCount()
	
	-- PDF pages are zero-based
	repeat with i from 0 to pageCnt - 1
		
		-- AppleScript words verb splits PDF text into list of words
		set pageWords to words of ((pdf's pageAtIndex:i)'s |string|() as text) as list
		(pageSet's addObjectsFromArray:pageWords)
		
		-- put the power of set intersections to work so that we can match all
		-- search words against the page's unique words in one command, leaving
		-- all matched words in the pageSet. No substring matches will occur.
		(pageSet's intersectSet:searchSet)
		
		-- use a dictionary to assign matched search words as keys, and found page
		-- numbers as a list per each key.
		repeat with match in pageSet's allObjects()
			
			-- if key is in dictionary then add the current page number
			if not (muDict's objectForKey:match) = missing value then
				-- and if key is in dictionary, then add the page number to its list
				set arr to (muDict's objectForKey:match)
				if not (arr's containsObject:(i + 1)) = true then
					(arr's addObject:(i + 1))
				end if
			else
				-- put the key in the dictionary and associate its page number
				(muDict's setObject:(NSMutableArray's array()) forKey:match)
				set arr to (muDict's objectForKey:match)
				-- remember the page index is off by 1
				(arr's addObject:(i + 1))
			end if
			
		end repeat
		-- clear for next page's words
		pageSet's removeAllObjects()
		
	end repeat


Aug 24, 2022 2:45 PM in response to VikingOSX

VikingOSX wrote:

The good news. I can provide you an AppleScript that uses your fixed-name word file to search the PDF, and a prompt for one or multiple PDFs in that AppleScript. Still generates one formatted text file per PDF. You double-click the AppleScript item on your Desktop and away you go. I am done for today. Automator has wore me out. If the AppleScript approach appeals to you, I can deliver that tomorrow.

this will be good. Sorry for brevity on phone. Tks!!

Sep 12, 2022 1:54 PM in response to VikingOSX

Ok. Apparently, the pdf findstring:word withOptions: cannot handle regular expressions such as a "\\baword\\b" pattern that would avoid matching aword as a substring. That means to avoid matching substrings, the script would have to be rewritten to loop through every page of the current PDF and apply a formal regular expression match on each page where aword occurs, and track the page number too. That is a lot more code and complexity than what exists now.

Aug 19, 2022 9:54 PM in response to mrchntmarine

I have something nearly coded in Automator that allows you to select a text file of words, select and extract text from a PDF, and then write the unique sorted list of matching words in the textual PDF contents to new text file with the PDF's name and "_matched.txt" appended. It has been tested on macOS 11.6.8, and before I am done, tested on macOS 12.5.1.


Presently, it allows you to select a single text file of words to match, and a single PDF, but as I thought I had finished it, I decided it might be more practical if it allowed you to select a group of PDFs and apply your word filter to each PDF, with a separate text report of matching words for each PDF.


It's late. Tomorrow.

Aug 21, 2022 10:42 AM in response to mrchntmarine

So here is what I have right now that is tested and working on macOS 11.6.8. Presently it is an Application, but simple enough to make into a Quick Action so you can right-click on one (or more) PDFs. I have used an Automator Get Specificed Finder Items action so the file containing the search words is referenced at the top of the workflow and passed into the code.


  1. Select one or more PDFs and process them in a loop:
    1. Read the file containing the search words and make an array of its words
    2. Loop through the PDFs:
      1. Make an output file with _matched.txt from the current PDF file. This will contain the matched words on a succesful run. There is your list, tied to the original PDF name that allows you to go back into Preview and do a contextual search.
      2. Get all of the text in the current PDF into an array
      3. Match the words in the searchFile's array to those in the PDF array, and write matches to the _matched.txt file
      4. Display a 5 second dialog indicating that there were no matches in a given PDF and then continue the loop.
      5. Clean up the PDF words array before the next PDF is read


This has taken longer than I planned caused by some gnarly syntax issues, but now have a reasonably fast solution. I would like to test this on macOS 12.5.1 before I post it here. Not expecting any issues, but Apple is full of surprises. If all goes well, I will have this posted here this afternoon (8/21).



Aug 23, 2022 3:46 AM in response to mrchntmarine

I will probably continue to poke at this further as I do not like a problem controlling the outcome. The other factor is that with Apple trying to eradicate all higher functioning scripting languages (e.g. Python, Ruby, Perl) on macOS except Swift, that also thins the solution catalog. I don't want to inform recipients that oh, you now need to install something else to make this work.


I have extracted the text from a 300 page PDF created by Adobe InDesign CS3 into a separate file, and when I feed that into Ruby, it splits that content into words with one line of code. And the Zsh shell can do this if the source of the input is a text file. But if I am passing in a variable that is a large cluster of text, then Automator fails. Maybe the answer is to write that PDF text to a consistently named text file, and then read it. That will be my next test.


It is also possible to programmatically search a PDF for specific words without needing to extract its text, and one could just perform the search in a loop, using each of your words, and showing which words matched. Slower, but also less complicated. Will be looking into that too.

Aug 24, 2022 7:46 AM in response to mrchntmarine

Would you be content with a text file containing the output of a PDF word search that looks like the following when searching a four-page PDF with the following words:


  • bogus
  • his
  • Hall
  • stranger
  • portmanteau


with the output results showing the name of the matched word, and a list of pages on which that word was found:


his                 1, 2, 3, 4                              
Hall                1, 2, 3, 4                              
stranger            1                                       
portmanteau         1



I am allowing for twenty-character search words and 40 characters for the page number matches. These are tweakable.


Right now, I have it working on a fixed search_word.txt file and a fixed four-page PDF, but the devil is in the details getting that formatting to work, and I still have to revise the code to process multiple PDFs, and adapt it to an Automator Quick Action. The cursing part is done, and I should have that QA posted this afternoon.

Aug 26, 2022 12:25 PM in response to mrchntmarine

Yes, the script was done with AppleScript, using optionally supported Objective-C classes and methods in Apple's development frameworks. I used some Objective-C data structures that are not available in AppleScript alone, and the Zsh shell in a handler (function) to format the printout, as AppleScript can't do that, and interferes with string formatting in Objective-C.


Yes, you can learn AppleScript, and several of Apple's and some third-partry applications provide AppleScript dictionary support to control their functionality. You can access those dictionary descriptions from the Script Editor's File menu > Open Dictionary… However, Apple's strategic direction is with the Swift Programming language which requires the installation of either Xcode (40GB) and the Swift Playground, or just the command line tools for Xcode (4GB) to gain access to the Swift interpreter, and its compilation suite. Swift is intended to build standalone applications, not to control their functionality as does AppleScript.


See the following. Most of the AppleScript links below point to much older content, as AppleScript has been around for decades, and Apple is not extending it with new features. You may see images of the Script Editor that don't look like it does now, but the basics (entering code, clicking the compile button to see if you have syntax errors, or running it and having it explode do to runtime errors) haven't changed much.


AppleScript: Beginner's tutorial

Introduction to AppleScript Language Guide

AppleScript Language Guide (PDF)

Learn AppleScript, 3rd Edition (Amazon)

AppleScript: The Missing Manual (Amazon)




This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Help with Searching .pdf's

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