AppleScript: Revised Document Statistics

This is a revised version of the clipboard document statistics script that I used some time ago. It now counts the paragraphs and includes a 1-button dialog box.

Count the number of characters, words and paragraphs in the clipboard
David R. -
To use place this script in your User Scripts folder in ~/Library/Scripts
set nChars to count (the clipboard)
set nWords to count words of (the clipboard)
set nParag to count paragraphs of (the clipboard)
display dialog "Characters: " & nChars & "
Words: " & nWords & "
Paragraphs: " & nParag buttons {"OK"} default button 1

Installing the script

To use the script just use the AppleScript Editor that ships with MacOS (search in side the utilities folder) and save this as a script in your Scripts folder in ~/Library/Scripts.

AppleScript: search clipboard text on

AppleScript: search clipboard text

When I’m working on something interesting I usually want to check if I’ve already mentioned it the blog. This script allows me to quickly open a new tab on Google Chrome and search on for a text that I’ve copied into the clipboard.

-- This script is based on a script of Computer World
set url1 to ""
tell application "System Events"
	set myquery to the clipboard
end tell
-- changes space to plus using function at end of file
set thequery to SaR(myquery, " ", "+")
tell application "Google Chrome"
	set theURL to url1 & thequery
	open location theURL
end tell
on SaR(sourceText, findText, replaceText)
	set {atid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, findText}
	set tempText to text items of sourceText
	set AppleScript's text item delimiters to replaceText
	set sourceText to tempText as string
	set AppleScript's text item delimiters to atid
	return sourceText
end SaR

You can easily adapt the script for your own use by changing the variable url1 in the conde. If you prefer to use Safari instead of Google Chrome that is also easy to change in the code above.

To use the script you can use the Script Editor (AppleScript Editor in previous versions of OS X) and then save the script in your User Scripts folder (~/Library/Scripts). If you prefer you can also download the applescript and the edit from there.

Posting to Blog from Quicksilver

I’ve managed do find a solution to post text from anywhere to this blog using quicksilver to select text from my text editor and send it directly to the Dave’s Conundrums. The trick is to use an applescript and execute it via QS. Technically the script was used to allow you to type directly in the 1st quicksilver window, but instead of using it to compose you can just paste de selected text with CMD+G. Also, as I use MultiMarkdown on the server side of the blog I can write my short posts in it and need not to worry about HTML and other things. Posting images is not possible … yet, but for most of the daily writing this is more than enough.

AppleScript: How to skip 30/rewind 10 seconds in iTunes?

With the launch of Podcasts for the iOS devices, Apple introduced two buttons on the device to skip 30 seconds (great for skipping advertisements, or Sarah Lane segments in Tech News Today) and to rewind 10 seconds for quick replay of something important that you missed.

Well, iTunes is my desktop app for podcast subscription and management and unfortunately these two buttons don’t exist in iTunes. For this I use two applescripts that I’ve labeled iTunes-Skip-30 and iTunes-Back-10. They sit in my scripts folder and any time I want to use them I just access the scripts from the top menu bar.

-- iTunes Skip 30
tell application "iTunes" to set player position to (player position + 30)
-- iTunes Back 10
tell application "iTunes" to set player position to (player position - 10)

You just need to use your Script Editor and save each of these scripts in your user scripts folder (usually in ~/Library/scripts/) and enable the scrips menu in the Scripts Utility.

AppleScript: Word Count, anywhere

Sometimes one needs to count the number of words and characters of text that we’ve written.

Here’s a small script to do just that:

set nChars to count (the clipboard)
set nWords to count words of (the clipboard)
display dialog "Characters: " & nChars & "
Words: " & nWords

Use Script Editor and paste the above code. Then save it to your scripts folder and every time you want to have word count just copy the text and invoke the script.

Do you need to insert the current Date and Time in your documents?

This is an AppleScript that inserts the current Date and Time in any document you are working on.


The script acts like Emacs with C-u M-! date or with vim‘s :r !date.

First of all I wanted the script to work across all my GUI apps in Leopard. So I resorted to AppleScript. After fiddling for a while with the grammar of the language I came up with a solution. The only problem was that I couldn’t launch the script from a keyboard shortcut.

Use Quicksilver to trigger Applescript

Luckily, quicksilver has triggers that you can configure to do almost anything. I mapped Shift+Command+- (hyphen) to run the AppleScript bellow. As a result, the script copies the current Date and Time to the clipboard and then asks the foremost application to paste it.

This works well and is cool to have the date on the clipboard for future pastes if I want. This is great keystroke saver for working with log files! Just use Script Editor and put it in your User Scripts Folder! A time saver!

-- Insert Date and Time into your documents
-- @2012 David Rodrigues
set date_ to ((current date) as string)
set the clipboard to the date_
tell application "System Events"
	set frontmostApplication to name of the first process whose frontmost is true
end tell
tell application frontmostApplication
	tell application "System Events"
		keystroke "v" using {command down}
	end tell
end tell

AppleScript: Close All

One of the problems with having a todo list bigger than the the Eiffel Tower is that sometimes I have more applications open than my computer would like to handle. To clean my desktop I could use a Logoff / Login sequence, but that would interfere with Dropbox synchronization and therefore I opted to use an AppleScript that closes all windowed applications.

The close all script that I use is the following:

-- Insert Date and Time into your documents
-- @2010 David Rodrigues
set exclude to {"Finder"}
tell application "System Events"
	set end of exclude to displayed name of (info for (path to frontmost application))
	set app_list to name of every process whose visible is true
end tell
repeat with this_app in app_list
	if this_app is not in exclude then
		tell application this_app
		end tell
	end if
end repeat

Remember, put the script in the ~/Library/Scripts folder (don’t forget to activate the “Show Script…” in Apple Script Utility

I now have a much cleaner desktop…