Features: A closer look at Journler
AppleScript
|
MacScripter Resources
MacScripter MacScripter BBS MacScripter ScriptBuilders |
Journler provides extensive support for AppleScript developers. The AppleScript dictionary ensures access to every item of a user's journal as well as the relationships between them. The rich text contents of an entry are accessible and may be modified. Entries, folders and resources can all be created and deleted. Finally, the scripting dictionary provides support for file importing and exporting.
Journler's comprehensive dictionary allows scripters to take full advantage of Journler's already incredible flexibility. To help you get started, example code for a number of common tasks is provided below.
The following examples were written in AppleScript and compiled into a single document in Journler before being exported as XHTML and posted here.
Getting the journal viewer, the main window in Journler
tell application "Journler"
tell the journal viewer
get the name of the first tib
end tell
end tell
Adding and removing a tab to/from a window
tell application "Journler"
tell the first window to make new tib
tell the first window
delete the last tib
end tell
end tell
Getting the visible entries in the front tab and window
tell application "Journler"
tell the selected tib of the first window
get the visible entries
end tell
end tell
Perform a search and get the results
tell application "Journler"
find in journal "Search Phrase"
tell the selected tib of the first window
get the visible entries
end tell
end tell
Highlight a phrase in the frontmost tab and window
tell application "Journler"
tell the selected tib of the first window
highlight "this phrase"
end tell
end tell
Getting the selected text in the front most tab using GUI scripting
tell application "Journler"
activate
tell application "System Events" to keystroke "c" using command down
set textSelection to the clipboard
end tell
Getting the currently selected entries by targeting a specific tab and window
(also works with date, folders, resources)
tell application "Journler"
tell the selected tib of the first window
get the selected entries
end tell
end tell
Getting the currently selected entries by targeting the application
(sends the command to the frontmost window and tab)
tell application "Journler"
get the selected entries
end tell
Setting the currently selected entries, folders, resources or date
(works at the application level or against a particular tab)
tell application "Journler"
set anEntry to (get the first item of (get the entries))
set the selected entries to {anEntry}
end tell
tell application "Journler"
set aResource to (get the first item of (get the resources))
set the selected resources to {aResource}
end tell
tell application "Journler"
set theFolders to (get the folders)
set the selected folders to {the first item of theFolders, the second item of theFolders}
end tell
tell application "Journler"
set lastBirthday to date "Friday, March 3, 2006 12:00:00 AM"
set the selected date to lastBirthday
end tell
Setting the textual contents of an entry
tell application "Journler"
set the rich text of the first entry to "Well how about that, I can set the content of an entry!"
set the color of the first word of the first entry to {65500, 0, 0}
set the size of the first word of the first entry to 16
set the font of the first word of the first entry to "Times New Roman"
end tell
Creating a new entry
tell application "Journler"
set anEntry to make new entry
set the name of anEntry to "My New Entry"
set the rich text of anEntry to "My new entry has content!"
end tell
Deleting an entry
(moves it to the trash)
tell application "Journler"
delete the first entry
end tell
tell application "Journler"
set theSelection to the selected entries
trash the first item of theSelection
end tell
Creating a new folder
tell application "Journler"
set aFolder to make new folder
set the name of aFolder to "My AppleScript Folder"
set the label of aFolder to green
end tell
Deleting a folder
(immediately removes it from the journal without warning)
tell application "Journler"
delete the last folder
end tell
Creating a new url based resource
tell application "Journler"
set anEntry to the first entry
set aResource to make new resource with properties {owner:anEntry, type:website, url:"http://journler.com"}
get the name of aResource
end tell
Creating a new adress book based resource
tell application "Address Book"
set myContactID to the id of my card
end tell
tell application "Journler"
set anEntry to the first entry
set aResource to make new resource with properties {owner:anEntry, type:contact, contact id:myContactID}
get the name of aResource
end tell
Creating a new internal based resource
(refers to another item in journler)
tell application "Journler"
set anEntry to the first entry
set aURI to the uri representation of the second entry
set aResource to make new resource with properties {owner:anEntry, type:internal, journler uri:aURI}
get the name of aResource
end tell
Creating a new file based resource
(media, aliased or not)
tell application "Finder"
set aFile to choose file
end tell
tell application "Journler"
set anEntry to the first entry
set aResource to make new resource with properties {owner:anEntry, type:media, original path:aFile, aliased:yes}
get the name of aResource
end tell
Adding and removing an entry to/from a folder
tell application "Journler"
set regularFolders to (every folder whose type is regular folder)
set aFolder to the first item of regularFolders
add the first entry to aFolder
remove the first entry from aFolder
end tell
Adding a folder to another folder
tell application "Journler"
set regularFolders to (every folder whose type is regular folder)
set aFolder to the first item of regularFolders
set targetFolder to the second item of regularFolders
add aFolder to targetFolder
end tell
Getting an entry's selected resource
(the resource that is automatically displayed when the entry is selected)
tell application "Journler"
set anEntry to the first item of (get the selected entries)
get the resource selection of anEntry
end tell
Exporting a file, resource or folder
tell application "Finder"
set aPath to choose folder
end tell
tell application "Journler"
tell the first entry
export in aPath as pdf
end tell
tell the first resource
export in aPath
end tell
tell the first folder
export in aPath as pdf without subfolders
end tell
end tell
Importing a file
tell application "Finder"
set aFile to choose file
end tell
tell application "Journler"
import aFile
end tell
Getting the path to the file based rich text contents of an entry
tell application "Journler"
set theSelectedEntries to get the selected entries
set anEntry to the first item of theSelectedEntries
set aPath to get the rich text path of anEntry
end tell
tell application "Finder"
set anAlias to POSIX file aPath as alias
open anAlias
end tell
Getting the path to the file based document of a media resource
tell application "Journler"
set fileResources to (get the resources whose type is media)
set aPath to (get the original path of the first item of fileResources)
end tell
tell application "Finder"
set anAlias to POSIX file aPath as alias
select anAlias
activate
end tell
Saving the changes you've made via AppleScript
(saves the journal and immediately updates all smart folders)
tell application "Journler"
save changes
end tell