Created
February 2, 2011 18:17
-
-
Save Zettt/808115 to your computer and use it in GitHub Desktop.
Grabs a set amount of paragraphs of Lipsum from lipsum.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Grabs a set amount of paragraphs of Lipsum from lipsum.com | |
-- | |
-- Created by Zettt on 2011-02-02 | |
-- Mac OS X Screencasts http://macosxscreencasts.com | |
-- | |
-- Original from Brett Terpstra | |
-- http://brettterpstra.com/random-lipsum-for-textexpander/ | |
-- | |
-- This script can be used with Keyboard Maestro, LaunchBar | |
-- or similar apps. | |
-- Note: This works in TextExpander, too, but TE seems to | |
-- have problems with dialogs. | |
-- | |
-- start=0 gives random lipsum, 1 starts from the beginning. | |
-- Get frontmost app and save it for re-activation later | |
tell application "System Events" | |
set frontmostApp to name of the first process whose frontmost is true | |
end tell | |
-- The dialog that's going to be displayed will become foreground | |
tell application "System Events" | |
activate | |
set amountDialog to display dialog "Amount" default answer ¬ | |
"2" buttons {"Cancel", "OK"} default button {"OK"} | |
if (button returned of amountDialog is "OK") and (text returned of amountDialog is not "") then | |
set amount to text returned of amountDialog -- user set length of ipsum | |
else if (button returned of amountDialog is "OK") and (text returned of amountDialog is "") then | |
set amount to "2" -- default length is 2 | |
else if (button returned of amountDialog is "Cancel") then | |
return | |
end if | |
end tell | |
-- Brett's original script | |
-- Esentially grabs lipsum | |
set cmd to "curl -s 'http://www.lipsum.com/feed/xml?amount=" & amount & "&what=paras&start=1'| xpath '//lipsum' 2>/dev/null | sed -e 's/<lipsum>//' -e 's/<\\/lipsum>//'| awk -F\"\\n\" '{print $1\"\\n\"}'" | |
set theResult to do shell script cmd | |
-- re-activate frontmost app | |
tell application frontmostApp to activate | |
-- Paste lipsum there | |
return theResult | |
-- PS: Sorry about this whole frontmost stuff thing, | |
-- but it seems like interactive input requires | |
-- some sort of activate this, then that work-aroundery... :-/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment