Send URL to Punakea AppleScript

Hello everybody

I'm trying to build an apple script, that adds a bookmark (.webloc) to Punakea. I used the Drop Box Script, that was added as a Folder Action, as a starting Point (in fact, it's pretty much the same besides the first few lines)

Here's what I have so far:

tell application "Camino"
tell front browser window
set theurl to URL of current tab
set theName to title of current tab as text
end tell
end tell

tell application "Finder"
set webloc to make new internet location file to theurl at desktop with properties {name:theName}
set DroppedFiles to {webloc}
end tell
# set scriptPath to (path to Folder Action scripts as Unicode text) & "tmp.scpt"

# Get the comment from Punakea prefs
tell application "System Events"
try
set pListFile to (((path to library folder from user domain) as string) & "Preferences:eu.nudgenudge.punakea.plist") as alias
set pList to contents of property list file (pListFile as Unicode text)
end try

set theComment to "###begin_tags###"

try
set tags to value of property list item "ManageFiles.DropBox.Tags" of pList

repeat with tag in tags
set theComment to theComment & "@" & tag & ";"
end repeat
on error
set theComment to theComment & "@untagged;"
end try

set theComment to theComment & "###end_tags###"
end tell

# Write comment on dropped files
repeat with aFile in DroppedFiles
set f to aFile as string

try
#tell application "System Events"
# attach action to folder f using file scriptPath
#end tell

tell application "Finder"
set comment of alias f to theComment
end tell
end try

end repeat

By playing around a bit I recognized that files which are added to the DropBox stay in there until you alter or add some tags. Only then the files will be moved to your "Files" Folder. Very usefull in this context.

This also happens to the bookmarks created with my script. But in my case I would like make this moving step instantly, because I thought about making default tag sets for bookmarks and that means the tags of an added bookmark aren't going to be altered for sure. (Also think about a script that applies a diffrent tag set if there is "google" in the title of your bookmark)

So my question is: How can make Punakea to move my files instantly to the "Files" Folder?

Thanks for any suggestions

Simon

Well, you would have to read

Well, you would have to read the appropriate Path from the preferences plist ( for the key 'ManageFiles.ManagedFolder.Location' ) and move the file there in the script itself. Punakea isn't applescriptable yet, so you have to do this manually for the time being, sorry!

Hope you can get it to work, please post the final script, I think there might be some other people in here who could use that :)

Johannes

hey there! Here's what I

hey there!

Here's what I have. I think it works well, at least until Punakea is scriptable. Please post your thoughts/problems/requests/...!

IMPORTANT:
You need to check "Generate additional folder structure for tags" in the "Manage Files" tab of your Punakea prefs, because your list of existing tags is based on this folder so it has to exist if you want to see a list of existing tags. Also if you have some strange tags in you list (maybe some you deleted), try to rebuild this tag-Folder (Punakea will do this for you!)...it will solve the problem.

do whatever you want with it. please post if you have improvements!

sometimes you don't see your file instantly in Punakea, you have to click "Clean up Tags Database" from the "Tools" Menu.

simon

__copy everything from here___

# make the webloc from camino to the desktop
tell application "Camino"
tell front browser window
set theurl to URL of current tab
set theName to title of current tab as text
end tell
end tell
set theName to my searchReplace(theName, ":", "-")
tell application "Finder"
set webloc to make new internet location file to theurl at desktop with properties {name:theName}
set DroppedFiles to {webloc}
end tell
# set scriptPath to (path to Folder Action scripts as Unicode text) & "tmp.scpt"

--the macintosh harddisk path (will use this later)
set hd to path to startup disk as text
set hd to my searchReplace(hd, ":", "")

# Get the comment from Punakea prefs
tell application "System Events"
try
set pListFile to (((path to library folder from user domain) as string) & "Preferences:eu.nudgenudge.punakea.plist") as alias
set pList to contents of property list file (pListFile as Unicode text)
end try

set theComment to "###begin_tags###"

(* previous version from nudgenudge
set tags to value of property list item "ManageFiles.DropBox.Tags" of pList
*)

--get a list of all existing tags called tags_lib
try
set tags_lib to {}
set tags_lib_ref to a reference to tags_lib

set tags_folder to value of property list item "ManageFiles.TagsFolder.Location" of pList
set tags_folder to my searchReplace(tags_folder, "/", ":")
set tags_folder to (hd & tags_folder & ":") as string

tell application "Finder"
set tags_folder_content to entire contents of folder tags_folder
set tags_folder_content_ref to a reference to tags_folder_content
end tell

repeat with each in tags_folder_content_ref
if (class of each) is folder then
copy (name of each & return) to end of tags_lib_ref
end if
end repeat

set tags_lib to my removeDuplicates(tags_lib_ref) --here it is!

--ask user for tags, display list of existing tags
tell application "Camino"
try
set tags to paragraphs of text returned of ¬
(display dialog ¬
"Enter your tags with a return after each entry. Note: Pleas be very exactly when typing your tags else a new tag will be created. Here is a list with your existing tags:" & return & return & tags_lib default answer return & return giving up after 120)

on error
display dialog "You've choosen to cancel, what do you want to do with the webloc on your desktop?" buttons {"Keep", "Trash"} default button 2 giving up after 20
set the button_pressed to the button returned of the result
if the button_pressed is "Trash" then
delete webloc
return
else
return
end if
end try
end tell

on error --ask user for tags, without list of existing tags
tell application "Camino"
try
set tags to paragraphs of text returned of ¬
(display dialog ¬
"Enter your tags with a return after each entry. Note: Pleas be very exactly when typing your tags else a new tag will be created." default answer return & return giving up after 60)

on error
display dialog "You've choosen to cancel, what do you want to do with the webloc on your desktop?" buttons {"Keep", "Trash"} default button 2 giving up after 20
set the button_pressed to the button returned of the result
if the button_pressed is "Trash" then
delete webloc
return
else
return
end if
end try
end tell
end try

try
repeat with tag in tags
set theComment to theComment & "@" & tag & ";"
end repeat
on error
set theComment to theComment & "@untagged;"
end try
set theComment to theComment & "###end_tags###"
end tell

# Write comment on dropped files
repeat with aFile in DroppedFiles
set f to aFile as string
try
#tell application "System Events"
# attach action to folder f using file scriptPath
#end tell
tell application "Finder"
set comment of alias f to theComment
end tell
end try
end repeat

# get the location of the punakea library
tell application "System Events"
set libPath to value of property list item "ManageFiles.ManagedFolder.Location" of pList as text
set libPath to my searchReplace(libPath, "/", ":")
set fullPath to (hd & libPath & ":1")
end tell

# move the file to the library
repeat with aFile in DroppedFiles
try
move aFile to fullPath

on error --if the File already exists
display dialog "There is already a File with the Name \"" & theName & "\" in your Punakea Library. If they are NOT THE SAME, you have to reaname one of them in order to get this Script working. Choose what to do with THIS File:" buttons {"Show in Punakea (edit: not working!)", "Keep", "Trash"} default button 3 giving up after 60
set the button_pressed to the button returned of the result
if the button_pressed is "Trash" then
delete aFile
else if the button_pressed is "Show in Punakea (edit: not working!)" then
-- action for 3rd button goes here
else
return
end if

end try
end repeat

to searchReplace(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end searchReplace

to removeDuplicates(a)
-- removes duplicate items from a list
script o
property p : a
end script
set b to {}
repeat with i from 1 to a's length
tell o's p's item i to if ({it} is not in b) then set b's end to it
end repeat
return b
end removeDuplicates

and the Safari

and the Safari Version:

__copy everything from here___

# make the webloc from camino to the desktop
tell application "Safari"
tell front window
set theurl to URL of current tab
set theName to name of current tab as text
end tell
end tell
tell application "Finder"
set webloc to make new internet location file to theurl at desktop with properties {name:theName}
set DroppedFiles to {webloc}
end tell
# set scriptPath to (path to Folder Action scripts as Unicode text) & "tmp.scpt"

--the macintosh harddisk path (will use this later)
set hd to path to startup disk as text
set hd to my searchReplace(hd, ":", "")

# Get the comment from Punakea prefs
tell application "System Events"
try
set pListFile to (((path to library folder from user domain) as string) & "Preferences:eu.nudgenudge.punakea.plist") as alias
set pList to contents of property list file (pListFile as Unicode text)
end try

set theComment to "###begin_tags###"

(* previous version from nudgenudge
set tags to value of property list item "ManageFiles.DropBox.Tags" of pList
*)

--get a list of all existing tags called tags_lib
try
set tags_lib to {}
set tags_lib_ref to a reference to tags_lib

set tags_folder to value of property list item "ManageFiles.TagsFolder.Location" of pList
set tags_folder to my searchReplace(tags_folder, "/", ":")
set tags_folder to (hd & tags_folder & ":") as string

tell application "Finder"
set tags_folder_content to entire contents of folder tags_folder
set tags_folder_content_ref to a reference to tags_folder_content
end tell

repeat with each in tags_folder_content_ref
if (class of each) is folder then
copy (name of each & return) to end of tags_lib_ref
end if
end repeat

set tags_lib to my removeDuplicates(tags_lib_ref) --here it is!

--ask user for tags, display list of existing tags
tell application "Camino"
try
set tags to paragraphs of text returned of ¬
(display dialog ¬
"Enter your tags with a return after each entry. Note: Pleas be very exactly when typing your tags else a new tag will be created. Here is a list with your existing tags:" & return & return & tags_lib default answer return & return giving up after 120)

on error
display dialog "You've choosen to cancel, what do you want to do with the webloc on your desktop?" buttons {"Keep", "Trash"} default button 2 giving up after 20
set the button_pressed to the button returned of the result
if the button_pressed is "Trash" then
delete webloc
return
else
return
end if
end try
end tell

on error --ask user for tags, without list of existing tags
tell application "Camino"
try
set tags to paragraphs of text returned of ¬
(display dialog ¬
"Enter your tags with a return after each entry. Note: Pleas be very exactly when typing your tags else a new tag will be created." default answer return & return giving up after 60)

on error
display dialog "You've choosen to cancel, what do you want to do with the webloc on your desktop?" buttons {"Keep", "Trash"} default button 2 giving up after 20
set the button_pressed to the button returned of the result
if the button_pressed is "Trash" then
delete webloc
return
else
return
end if
end try
end tell
end try

try
repeat with tag in tags
set theComment to theComment & "@" & tag & ";"
end repeat
on error
set theComment to theComment & "@untagged;"
end try
set theComment to theComment & "###end_tags###"
end tell

# Write comment on dropped files
repeat with aFile in DroppedFiles
set f to aFile as string
try
#tell application "System Events"
# attach action to folder f using file scriptPath
#end tell
tell application "Finder"
set comment of alias f to theComment
end tell
end try
end repeat

# get the location of the punakea library
tell application "System Events"
set libPath to value of property list item "ManageFiles.ManagedFolder.Location" of pList as text
set libPath to my searchReplace(libPath, "/", ":")
set fullPath to (hd & libPath & ":1")
end tell

# move the file to the library
repeat with aFile in DroppedFiles
try
move aFile to fullPath

on error --if the File already exists
display dialog "There is already a File with the Name \"" & theName & "\" in your Punakea Library. If they are NOT THE SAME, you have to reaname one of them in order to get this Script working. Choose what to do with THIS File:" buttons {"Show in Punakea (edit: not working!)", "Keep", "Trash"} default button 3 giving up after 60
set the button_pressed to the button returned of the result
if the button_pressed is "Trash" then
delete aFile
else if the button_pressed is "Show in Punakea (edit: not working!)" then
-- action for 3rd button goes here
else
return
end if

end try
end repeat

to searchReplace(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end searchReplace

to removeDuplicates(a)
-- removes duplicate items from a list
script o
property p : a
end script
set b to {}
repeat with i from 1 to a's length
tell o's p's item i to if ({it} is not in b) then set b's end to it
end repeat
return b
end removeDuplicates

Great, works for me! I have

Great, works for me! I have noticed some references to Camino in the Safari Script, is this a problem if you do not have Camino installed?

I will really try to get Punakea to support AppleScript soon :)

uupps...sorry I forgot to

uupps...sorry I forgot to change that!

Simply replace the two tell application "Camino" with a tell application "Safari"