Skip to content

Instantly share code, notes, and snippets.

View benwaldie's full-sized avatar

Ben Waldie benwaldie

View GitHub Profile
@benwaldie
benwaldie / textedit_find_replace.applescript
Last active January 10, 2022 16:32
Find and replace text in an opened TextEdit document using AppleScript.
-- Find and replace a single word in an opened TextEdit document
tell application "TextEdit"
make new document
-- Add some text to the document
set text of front document to "The quick fox jumped over the lazy dog."
-- Find and replace
set every word of front document where it = "fox" to "elephant"
end tell
@benwaldie
benwaldie / 2012-12-09-TUAW_Waldie.applescript
Created December 9, 2012 18:34
TUAW - Send Keynote Presenter Notes to Evernote with AppleScript
-- Make sure a presentation is opened in Keynote. If not, notify the user and stop.
tell application "Keynote"
if (front slideshow exists) = false then
display alert "Unable to proceed." message "Please open a presentation in Keynote."
return
end if
set extractBody to button returned of (display alert "Would you like to extract slide content too?" buttons {"Yes", "No"}) = "Yes"
-- Target the front presentation.
@benwaldie
benwaldie / 2013-04-21-TUAW_Waldie.applescript
Created April 22, 2013 02:02
TUAW > Extract App Resource Icons with AppleScript
-- Ask the user to select an app
set theApp to choose file of type "app" default location (path to applications folder)
-- Get the app name
tell application "System Events"
set theAppName to name of theApp
if theAppName ends with ".app" then set theAppName to text 1 thru -5 of theAppName
-- Determine whether the app is a package, and notify the user if it's not
set isPackage to (package folder of theApp)
@benwaldie
benwaldie / 2013-02-10-TUAW_Waldie.applescript
Created February 11, 2013 01:39
TUAW > Elapsed Time Calculator
-- Ask the user to enter a date. Note, if no time is specified, then the date will default to 12:00 AM.
set theDate to text returned of (display dialog "Please enter a starting date:" default answer "8/9/1997 12:00PM" with icon note with title "Elapsed Time Calculator")
-- Coerce the entered date to an AppleScript date
set theDate to date theDate
-- Get the current date
set theCurrentDate to current date
-- Determine the number of months, years, seconds, minutes, hours, days, and weeks
@benwaldie
benwaldie / 2014-04-03 Send Keynote Presenter Notes to Evernote.applescript
Created April 3, 2014 14:14
This script sends presenter notes from a Keynote 6.2 presentation to Evernote.
--==============================
-- Send Keynote Presenter Notes to Evernote
-- Version 1.0.1
-- Written By: Ben Waldie <ben@automatedworkflows.com>
-- http://www.automatedworkflows.com
-- Version 1.0.0 - Initial release
-- Version 1.0.1 - Updated for Keynote 6.2 compatibility
--==============================
@benwaldie
benwaldie / 2013-04-12-TUAW_Waldie.applescript
Created April 12, 2013 18:17
TUAW > OmniFocus > Prepare Task Completion Report
-- This property controls whether full project paths (including parent folders) are displayed
property includeFullProjectPaths : true
-- These properties control whether additional task content is displayed
property includeTaskContext : true
property includeTaskEstimatedTime : true
property includeTaskStartDate : true
property includeTaskModificationDate : true
property includeTaskCompletionDate : true
property includeTaskNotes : true
@benwaldie
benwaldie / saveSelectedMailAttachments.applescript
Created October 27, 2016 19:03
Save Selected Mail Message Attachments
set theSavePath to path to desktop folder as string
tell application "Mail"
selection
set theMessage to item 1 of result
set theAttachments to every mail attachment of theMessage
repeat with anAttachment in theAttachments
set theName to name of anAttachment
save anAttachment in file (theSavePath & theName)
end repeat
end tell
@benwaldie
benwaldie / Example.applescript
Created December 2, 2013 20:45
Get the address from a selected contact and add it to a Pages '09 document, right aligned, with the date.
tell application "Contacts"
set theSelection to selection
set thePerson to item 1 of theSelection
set theAddress to address 1 of thePerson
set theAddressText to formatted address of theAddress
end tell
set theDate to short date string of (current date)
tell application "Pages"
@benwaldie
benwaldie / NC_Enable_DoNotDisturb.applescript
Created June 4, 2013 19:55
Notification Center > Enable Do Not Disturb Tested with 10.8.3
do shell script "defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean true"
set theDate to quoted form of (do shell script "date -u +\"%Y-%m-%d %H:%M:%S +0000\"")
do shell script "defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturbDate -date " & theDate
do shell script "killall NotificationCenter"
@benwaldie
benwaldie / NC_Disable_DoNotDisturb.applescript
Created June 4, 2013 19:56
Notification Center > Disable Do Not Disturb Tested with 10.8.3
do shell script "defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean false"
try
do shell script "defaults -currentHost delete ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturbDate"
end try
do shell script "killall NotificationCenter"