The Flying Meat Wiki : VDPASExamples

HomePage :: Categories :: PageIndex :: RecentChanges :: Login/Register
Oldest known version of this page was edited on 2008-01-24 22:43:58 by BradEllis []
Page view:

Here are some snippets of AppleScript that you might find handy.


Note: These are examples that work in VoodooPad 3.5. If you have a previous version of VoodooPad, check the help files that came with that version. For folks with VoodooPad Pro, just substitute "VoodooPad Pro" where you see "VoodooPad below.

Prepend to the top of a page:
tell application "VoodooPad"
	tell page "index" of document 1 to prepend text "this goes at the top" & return
end tell


Append to the bottom of a page:

tell application "VoodooPad Pro"
	tell page "junk" of document 1 to append text "this goes at the bottom" & return
end tell


Create a new page:

tell application "VoodooPad"
	tell document 1 to create new page with name "new page" with content "This is a new page."
end tell


Export to iPod:

tell application "VoodooPad"  
  -- this is the path to your document.
  open "srv:Users:gus:Desktop:astest.vdoc" as alias
  tell front document
	export to ipod
  end tell
end tell


Getting text from a specific page:

tell application "VoodooPad"
	set theString to (text of page "index" of document 1) as string
end tell


An example that loops through all the pages and displays it's name and contents

tell application "VoodooPad"
	tell document 1
	    repeat with i from 1 to number of items in pages
	        set s to text of page i
	        set n to name of page i
	        display dialog n & return & s
	    end repeat
	end tell
end tell


An example that loops through all the pages, and prepends some text to every page

tell application "VoodooPad"
	repeat with i from 1 to number of items in pages of document 1
		set n to name of page i of document 1
		tell page n of document 1 to prepend text "this goes at the top" & return
	end repeat
end tell


Sort and pull out pages by create page:

tell application "VoodooPad Pro"
	set theDoc to first document
	tell theDoc
		
		set myList to ordered names sorted by create date
		
		repeat with idx from 1 to number of items in myList
			set pageName to item idx of myList
			set s to text of (page pageName of theDoc)
			-- now do something exciting with s
		end repeat
		
		-- we could have also done:
		-- set myList to ordered names sorted by modified date
		-- set myList to ordered names -- default, sorted by key
		
	end tell
end tell


Call into VoodooPad's scripting language "Lua" from AppleScript (it's kind of crazy)

tell application "VoodooPad Pro"
	set s to "print 'Hello World!'; table.foreach(applescriptProperties, print); applescriptProperties.output = 'Hello from the return value!'"
	tell window 1
		set x to use plugin named "Lua Script" with properties {source:s, aprop:"This is a property passed in"}
		display dialog x
	end tell
	
	set s to "applescriptProperties.output = windowController:textView():string()"
	tell window 1
		set x to use plugin named "Lua Script" with properties {source:s}
		display dialog (x as string)
	end tell
end tell


Fun with Meta Values

tell application "VoodooPad Pro"
	set currentPage to current page name
	
	tell page currentPage of document 1 to add meta record with value {|the key|:"the value"}
	
	activate
	display dialog "did it add?"
	
	set thePageMeta to meta record of page currentPage of document 1
	
	set s to |the key| of thePageMeta
	
	display dialog s
	
	tell page currentPage of document 1 to remove meta record with key "the key"
	
	delay 1
	
	display dialog "did it go away?"
end tell


Fun with Categories

tell application "VoodooPad Pro"
	set currentPage to current page name
	activate
	tell page currentPage of document 1 to add category named "foo"
	delay 1
	display dialog "did it add?"
	tell page currentPage of document 1 to remove category named "foo"
	delay 1
	display dialog "did it remove?"
end tell
tell application "VoodooPad Pro"
	activate
	tell document 1 to add category named "Foo"
	delay 1
	display dialog "did it add?"	
	tell document 1 to remove category named "Foo"
	delay 1
	display dialog "did it remove?"	
end tell
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.3
Page was generated in 0.0316 seconds