Sample AppleScript Test

June 29th, 2004  |  Published in AppleScript

<

div class=’codeblock’> Open this script in a new Script Editor window.

change this to be the base path of your tasks site

property kUrlToTasks : "http://tasks.samdevore.com/"
property kDefaultTasksID : 27


on encode_text(this_text)
    set the acceptable_characters to "abcdefghijklmnopqrstuvwxyz0123456789_"
    set the encoded_text to ""
    set the character_list to {}
    repeat with this_char in this_text
        set this_char to the contents of this_char
        if this_char is in the acceptable_characters then
            set the end of the character_list to this_char
        else
            set the end of the character_list to encode_char(this_char)
        end if
    end repeat
    return (the character_list) as string
end encode_text

this sub-routine is used to encode a character
on encode_char(this_char)
    set the ASCII_num to (the ASCII number this_char)
    set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
    set x to item ((ASCII_num div 16) + 1) of the hex_list
    set y to item ((ASCII_num mod 16) + 1) of the hex_list
    return ("%" & x & y) as string
end encode_char

on addToTask(theTitle, theUrl, theID)
    set theLocation to kUrlToTasks & "index.php?screen=edit&id=" & theID & "&task_notes_append="
    set theLocation to theLocation & encode_text("<li><a href=\"" & theUrl & "\" rel=\"external\">" & theTitle & "</a></li>")
    tell application "System Events"
        open location theLocation
    end tell
end addToTask

tell application "NetNewsWire"
    set theTitle to title of selectedHeadline
    set theUrl to URL of selectedHeadline
    tell application "Safari"
        set this_URL to the URL of document 1
    end tell
    – default id to append to
    set idNumber to kDefaultTasksID
    set AppleScript’s text item delimiters to "?"
    set the item_list to every text item of this_URL
    set AppleScript’s text item delimiters to ""
    if item 1 of item_list contains kUrlToTasks then
        set params to item 2 of item_list
        set AppleScript’s text item delimiters to "&"
        set the param_list to every text item of this_URL
        set AppleScript’s text item delimiters to ""
        repeat with param in param_list
            if param contains "id" then
                set AppleScript’s text item delimiters to "="
                set idNumber to text item 2 of param
                set AppleScript’s text item delimiters to ""
            end if
        end repeat
        –else
        –    display dialog "Not your tasks page in Safari" & item 1 of item_list
    end if
    
    my addToTask(theTitle, theUrl, idNumber)
end tell

Comments are closed.