Editor & Examples From Your Applications Folder
Applications > AppleScript > Script Editor.app
Applications > AppleScript > Example Scripts

AppleScript website
< http://www.apple.com/macosx/features/applescript/>
The AppleScript website. It includes tutorials, example scripts, and other information about writing scripts. It also contains information about the AppleScript reference manual, which you'll need to become a proficient script writer.
AppleScript Language Guide (PDF):
http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/AppleScriptLanguageGuide.pdf

AppleScript Language Guide (HTML):
<http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/>

Scripting Additions
< http://download.info.apple.com/Apple_Support_Area/Manuals/software/0305098AASADDGENG.PDF >

http://macscripter.net/
http://osaxen.com/
A source of tutorials, scripts, and scripting additions (OSAX  Open Scripting Architecture Extension)
Shazam
<http://scriptbuilders.net/files/shazam2.0.html>
A collection of simple scripts for beginning scripters. Conveniently, some of them also show off the "Gee Whiz" factor of a Mac, to impress your Windows-using friends. All scripts are editable and have comments that describe how to use them. Scripts included for iCal, TextEdit, Appleworks, iTunes, and the Finder! 

Activity Monitor
~:Applications:Utilities:Activity Monitor.app:

Third Party Help

"AppleScript: The Definitive Guide" is written for anyone who is interested in putting their Mac to work by becoming more knowledgeable about AppleScript, be they novices, power users, or graphics professionals. The book is a thorough, straightforward reference and installation guide in which Neuberg endeavors to explain everything Mac users need to know about AppleScript; what it is, why it exists, how it works, and how to make it perform better, smoother, and faster.

Cancel Printing =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-- This scripts cancels all print jobs
do shell script "cancel -a -"
display dialog "No more printing jobs" buttons ["OK"] default button 1

CompareFolders =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-- 
-- Choose two folders to compare
-- List name, modification date, file size, & path of each file
-- Discard files that match on name, modification date, file size
-- Visually check remaining files
-- 

global newTextFinal
global foo
global folderFirst
global folderSecond
global parentFolderString
global fileCount
global fileSize
global intro
global countFirst
global countSecond
global myMarker
global marker1Location
global marker2Location
global listOfNames
global nameList
global sortedNameList

set newTextFinal to ""
set fileCount to 0
set countFirst to 0
set countSecond to 0
set myMarker to "†"
set listOfNames to {}
set sortedNameList to {}

tell application "Finder"
	activate
	say "Choose the first folder."
	choose folder
	set folderFirst to result as alias
	say "Choose the second folder."
	choose folder
	set folderSecond to result as alias
	set intro to "Scan of " & folderFirst & " and " & folderSecond as text
	set intro to intro & " occurred on " & (the (current date) as text)
	
	-- Go through both folders getting info from each file
	say "Processing the first folder."
	my processFolder(folderFirst)
	set countFirst to fileCount
	say "Processing the second folder."
	my processFolder(folderSecond)
	set countSecond to (fileCount - countFirst)
	-- my removeWindows()
	
	-- Sort files by file name
	(*
	Place the quicksort script (the script after this one) in a folder named 
“ Script Library” which is in a folder named “Scripts” which is in your Users’ “Library” folder. Name the script “ MultiSort.scpt”
	*)
	say "Sorting"
	set scriptPath to (path to scripts folder from user domain) & "Script Library:"
	set sortLib to load script ((scriptPath as text) & "MultiSort.scpt") as alias
	set sortedNameList to sortLib's quickSort(listOfNames)
	
	-- check for duplicate through myMarker
	-- if two paragraphs match, remove them
	-- Save non-matching items for "Tex-Edit Plus"
	(*
	We placed a special character (the marker) behind the file size,
	so that we can compare the name, modification date, & file size
	of the files.
	*)	
	-- go through list and remove exact duplicates
	say "Removing duplicates."
	set nameList to ""
	set listCount to length of sortedNameList
	say listCount as text
	set currentItemIndex to 2
	
	repeat while currentItemIndex ≤ listCount
		try
			set marker1Location to the offset of myMarker in (item currentItemIndex of sortedNameList)
			set marker2Location to the offset of myMarker in (item (currentItemIndex - 1) of sortedNameList)
			if characters 1 through marker1Location of (item currentItemIndex of sortedNameList) is equal to characters ¬
				1 through marker2Location of (item (currentItemIndex - 1) of sortedNameList) then
				-- Got an exact match: skip past them
				set currentItemIndex to currentItemIndex + 2
			else
				-- Not a match: save the first and move forward one place
				set nameList to nameList & item (currentItemIndex - 1) of sortedNameList & return
				set currentItemIndex to currentItemIndex + 1
				
			end if
			
			-- report progress and set up for next loop
			if (listCount - currentItemIndex) mod 100 = 0 then
				set wayToGo to (listCount - currentItemIndex) as text
				say wayToGo
			end if
			
		on error errorMessage number errorNumber
			if errorNumber ≠ -1728 then display dialog errorMessage
		end try
	end repeat
	
end tell

tell application "Tex-Edit Plus"
	make new document
	set the name of window 1 to "Junk List 2"
	
	-- now create the report & display it
	set newTextFinal to intro & return ¬
		& nameList & return ¬
		& ("Processed " & countFirst as text) & " files from " & folderFirst & return ¬
		& ("Processed " & countSecond as text) & " files from " & folderSecond & return
	
	set text of front document to newTextFinal
	say "Your scan is now complete." using "Victoria"
end tell

on processFolder(whichFolder)
	local listOfFolders
	set parentFolderString to whichFolder as string
	-- set folderCount to folderCount + 1
	
	tell application "Finder" -- reqd to get lists
		get (every file of whichFolder)
		set listOfFiles to result
		repeat with itemInFileList in listOfFiles
			set currentFileInList to itemInFileList as alias
			my processFile(currentFileInList)
		end repeat
		
		get (every folder of whichFolder)
		set listOfFolders to result
		repeat with theNextFolder in listOfFolders
			my processFolder(theNextFolder)
		end repeat
		
		my removeWindows()
		
	end tell
end processFolder

on processFile(whichFile)
	set fileCount to fileCount + 1
	
	-- report progress and set up for next loop
	if fileCount mod 100 = 0 then
		say fileCount as text
	end if
	
	tell application "Finder"
		set foo to info for whichFile
		
		my DateToMMDDYY(modification date of foo)
		set modDate to result
		
		set theSize to size of foo as integer
		-- my KorM(theSize)
		set fileSize to result
		
		-- List name, modification date, file size, & path
		-- Save in work area first
		-- otherwise each field becomes an item in the list.
		set workArea to name of foo & tab ¬
			& modDate & tab ¬
			& fileSize & tab ¬
			& myMarker & tab ¬
			& parentFolderString
		
		set listOfNames to listOfNames & workArea
	end tell
end processFile

-- Return the current date as the string "MM/DD/YY"
on DateToMMDDYY(modDate)
	-- set todaysDate to (current date)
	set {d, m, y} to {day, month, year} of modDate
	set monthList to {January, February, March, April, May, ¬
		June, July, August, September, October, November, ¬
		December}
	repeat with km from 1 to 12
		if m = (item km of monthList) then
			set monthString to text -2 thru -1 of ("0" & km)
			exit repeat
		end if
	end repeat
	set dayString to text -2 thru -1 of ("0" & d)
	set todaysDate to monthString & "/" & dayString & "/" & y
end DateToMMDDYY

-- Remove windows
on removeWindows()
	tell application "Finder"
		set windowCount to count of windows
		if windowCount > 0 then
			close every window
		end if
	end tell
end removeWindows

-- Convert size to MBs or Ks
on KorM(whatNumber)
	if whatNumber > 1048576 then
		set inSize to (round (whatNumber / 1.048576E+5) rounding up) as string
		set outSize to (get characters 1 through ((count of inSize) - 1) of inSize) ¬
			& "." & (get character (count of inSize) of inSize) & " MB"
	else if whatNumber > 1024 then
		set outSize to ((round (whatNumber / 1024) rounding up) as string) & " K"
	else
		set outSize to whatNumber as string
	end if
	return outSize
end KorM

MultiSort =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
(*
This script needs to be placed in the User’s folder (~:Users:nameOfUser:Library:Scripts:Script Library:) with the file name “ MultiSort.scpt”
*)
---
-- quickSort handler
-- takes a list, returns it sorted
to quickSort(theList)
	--public routine, called from your script
	script bs
		property aList : theList
		
		on Qsort(leftIndex, rightIndex)
			--private routine called by quickSort. 
			--do not call from your script!
			if rightIndex > leftIndex then
				set pivot to ((rightIndex - leftIndex) div 2) + leftIndex
				set newPivot to Qpartition(leftIndex, rightIndex, pivot)
				set theList to Qsort(leftIndex, newPivot - 1)
				set theList to Qsort(newPivot + 1, rightIndex)
			end if
			
		end Qsort
		
		on Qpartition(leftIndex, rightIndex, pivot)
			--private routine called by quickSort. 
			--do not call from your script!
			set pivotValue to item pivot of bs's aList
			set temp to item pivot of bs's aList
			set item pivot of bs's aList to item rightIndex of bs's aList
			set item rightIndex of bs's aList to temp
			set tempIndex to leftIndex
			repeat with pointer from leftIndex to (rightIndex - 1)
				if item pointer of bs's aList ≤ pivotValue then
					set temp to item pointer of bs's aList
					set item pointer of bs's aList to item tempIndex of bs's aList
					set item tempIndex of bs's aList to temp
					set tempIndex to tempIndex + 1
				end if
			end repeat
			set temp to item rightIndex of bs's aList
			set item rightIndex of bs's aList to item tempIndex of bs's aList
			set item tempIndex of bs's aList to temp
			
			return tempIndex
		end Qpartition
		
	end script
	
	if length of bs's aList > 1 then bs's Qsort(1, length of bs's aList)
	return bs's aList
end quickSort

ListFiles =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
-- This script lists either “All” of the files within a folder
-- or just the “Duplicates”
--
-- Select a folder to examine
-- Decide whether to display "All" files or just "Duplicate" (first word only)
-- 

global newText
global newTextFinal
global finalText
property foo : ""
property currentFolder : ""
global parentFolderString
property myShortVersion : ""
global folderCount
global fileCount
global myLongVersion
global fileSize
global isDuplicate
global intro
global theParagraphTab
global nextParagraphTab
global currentParagraph
global nextParagraph

set newText to ""
set newTextFinal to ""
set folderCount to 0
set fileCount to 0
set isDuplicate to false
set finalText to ""

tell application "Finder"
	activate
	choose folder
	set currentFolder to result as alias
	set intro to "Scan of " & currentFolder as text
	set intro to intro & " occurred on " & (the (current date) as text)
	
	-- Determine what to list
	set prompt to "List 'All' or 'Duplicates'?"
	set dialogResult to display dialog prompt buttons {"All", "Duplicates"}
	if button returned of dialogResult is "Duplicates" then
		set isDuplicate to true
	end if
	
	-- Go through currentFolder checking each file
	my processFolder(currentFolder)
	my removeWindows()
end tell

tell application "Tex-Edit Plus"
	if isDuplicate then
		launch
		make new document
		set the name of window 1 to "Junk List 1"
		set text of front document to newText
		say "Sorting"
		with timeout of 600 seconds
			sort text of front document cases ignored 1
		end timeout
		set newText to text of front document
	end if
end tell

tell application "Finder"
	if isDuplicate then
		-- check for duplicate through first tab
		-- if two paragraphs match 
		-- set them aside for visual check
		
		set paragraphCount to count of paragraphs of newText
		say "Extracting duplicates."
		say paragraphCount as text
		set currentParagraphIndex to 1
		set spaceCharacter to " "
		set characterPreviousLength to 0
		set characterCurrentLength to 0
		
		with timeout of 600 seconds
			repeat while currentParagraphIndex < paragraphCount
				try
					
					-- if length of paragraph currentParagraphIndex of text of front document > 0 then
					set currentParagraph to paragraph currentParagraphIndex of newText
					set nextParagraph to paragraph (currentParagraphIndex + 1) of newText
					set theParagraphTab to the offset of tab in currentParagraph
					set nextParagraphTab to the offset of tab in nextParagraph
					
					if (theParagraphTab > 0) and (nextParagraphTab > 0) then
						if characters 1 through theParagraphTab of currentParagraph is equal to the characters ¬
							1 through nextParagraphTab of nextParagraph then
							set finalText to finalText & paragraph currentParagraphIndex of newText & return ¬
								& paragraph (currentParagraphIndex + 1) of newText & return & return
							-- set currentParagraphIndex to currentParagraphIndex + 1
						end if
					end if
					
					-- report progress and set up for next loop
					if (paragraphCount - currentParagraphIndex) mod 100 = 0 then
						set wayToGo to (paragraphCount - currentParagraphIndex) as text
						say wayToGo
					end if
					set currentParagraphIndex to currentParagraphIndex + 1
					
				on error errText
					log errText
					set currentParagraphIndex to currentParagraphIndex + 1
					
				end try
			end repeat
		end timeout
		set newText to finalText
	end if
end tell

tell application "Tex-Edit Plus"
	launch
	make new document
	set the name of window 1 to "Junk List 2"
	-- now create the report & display it
	set newTextFinal to intro & return ¬
		& newText & return ¬
		& ("Processed " & folderCount as text) & " folders." & return ¬
		& ("Processed " & fileCount as text) & " files." & return
	set text of front document to newTextFinal
	say "Your scan is now complete." using "Victoria"
end tell

on processFolder(whichFolder)
	local listOfFolders
	set parentFolderString to whichFolder as string
	set folderCount to folderCount + 1
	
	tell application "Finder" -- reqd to get lists
		get (every file of whichFolder)
		set listOfFiles to result
		repeat with itemInFileList in listOfFiles
			set currentFileInList to itemInFileList as alias
			my processFile(currentFileInList)
		end repeat
		
		get (every folder of whichFolder)
		set listOfFolders to result
		repeat with theNextFolder in listOfFolders
			my processFolder(theNextFolder)
		end repeat
		
		my removeWindows()
		
	end tell
end processFolder

on processFile(whichFile)
	set fileCount to fileCount + 1
	
	-- report progress and set up for next loop
	if fileCount mod 100 = 0 then
		say fileCount as text
	end if
	
	tell application "Finder"
		set foo to info for whichFile
		
		try
			set myShortVersion to short version of foo as text
		on error
			set myShortVersion to space
		end try

		my DateToMMDDYY(modification date of foo)
		set modDate to result
		
		set theSize to size of foo as integer
		my KorM(theSize)
		set fileSize to result
		
		-- List name / modification date / file size / folder
		set newText to newText & ¬
			name of foo & tab ¬
			& modDate & tab ¬
			& fileSize & tab ¬
			& parentFolderString & return
		
	end tell
end processFile

-- Return the current date as the string "MM/DD/YY"
on DateToMMDDYY(modDate)
	-- set todaysDate to (current date)
	set {d, m, y} to {day, month, year} of modDate
	set monthList to {January, February, March, April, May, ¬
		June, July, August, September, October, November, ¬
		December}
	repeat with km from 1 to 12
		if m = (item km of monthList) then
			set monthString to text -2 thru -1 of ("0" & km)
			exit repeat
		end if
	end repeat
	set dayString to text -2 thru -1 of ("0" & d)
	set todaysDate to monthString & "/" & dayString & "/" & y
end DateToMMDDYY

-- Remove windows
on removeWindows()
	tell application "Finder"
		set windowCount to count of windows
		if windowCount > 0 then
			close every window
		end if
	end tell
end removeWindows

on KorM(whatNumber)
	if whatNumber > 1048576 then
		set inSize to (round (whatNumber / 1.048576E+5) rounding up) as string
		set outSize to (get characters 1 through ((count of inSize) - 1) of inSize) ¬
			& "." & (get character (count of inSize) of inSize) & " MB"
	else if whatNumber > 1024 then
		set outSize to ((round (whatNumber / 1024) rounding up) as string) & " K"
	else
		set outSize to whatNumber as string
	end if
	return outSize
end KorM

ListCharacters =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
-- Use this script to display the small set of characters available in a font.
-- After the characters are displayed, select all of the characters and then 
-- use ctl-t to display the available fonts. Individual characters can be copied
-- and pasted into your own text processor.

global newText
global myCharacter
global myText
set newText to "Use command-T to display fonts" & return & return
set myCharacter to -1
set myText to "Now is the time for all good men to come to the aid of their country."

tell application "System Events"
	
	repeat 14 times
		repeat 16 times
			
			set myCharacter to myCharacter + 1
			set newText to newText & (ASCII character myCharacter) & space & space
			
		end repeat
		set newText to newText & return
	end repeat
	set newText to newText & return & return
	set newText to newText & myText
	
end tell

tell application "TextEdit"
	activate
	if (count of windows) = 0 then
		make document
	end if
	set text of front document to newText
end tell