Sorry for the late reply. I’m having Internet issues. Certainly, I will post the concept and code.
Essentially I wanted a way to record the current date, the title and URL of a website that I wanted to archive in a list. MySQL was a go-to for this. Seeing that I use Safari, I would need an AS hook.
To write to the database, I have that 3-field database on my workstation. I write using this AS which I call with Launchbar:
tell application "Safari"
set myU to the URL of the current tab in window 1
set myT to the name of the current tab in window 1
if myT begins with "â–¶ " then
-- Youtube Title leader for playing videos - take this stuff out
set myT to (characters 3 thru end of myT) as text
end if
end tell
set mysql_db to "myDB"
set mysql_table to "urls"
set mysql_user to "myUsername"
set mysql_host to "localhost"
set mysql_pw to "myPassword"
set myStatement to "/usr/local/mysql/bin/mysql -u " & mysql_user & " -h " & mysql_host & " -p" & mysql_pw & " -e \"INSERT INTO " & mysql_db & "." & mysql_table & " (title, url, creation_date) VALUES ('" & myT & "','" & myU & "', now())\";"
do shell script myStatement
Once in a while, I’d like those records returned to me so I can do something with them. I want to take the single string return which is delimited by “\r” and “\t” for records and fields, and shove them into my own array. Each entry is a record. Each entry is an array itself, of the fields returned of creation_date, url and title.
set mysql_db to "myDB"
set mysql_table to "urls"
set mysql_user to "myUsername"
set mysql_host to "localhost"
set mysql_pw to "myPassword"
set statement to "/usr/local/mysql/bin/mysql -u " & mysql_user & " -h " & mysql_host & " -p" & mysql_pw & " -e \"SELECT creation_date, url, title FROM " & mysql_db & ".urls ORDER BY id ASC\";"
set results to do shell script statement
set entries to splitString(results, "
")
set finished to {}
repeat with i in entries
set innerItems to splitString(i, " ")
set end of finished to innerItems
end repeat
-- take out first record as it is solely fieldnames
set final to rest of finished
set a to final
set textOut to ""
set counter to 0
-- build final text
repeat with i in final
set counter to counter + 1
set textOut to textOut & ((counter as text) & ". " & ((first item of i as text) & ": <a href=\"" & second item of i as text) & "\" target=\"_blank\">" & third item of i as text) & "</a>
"
end repeat
-- provide a method for final text viewing
set b to textOut
on replace_chars(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 replace_chars
to splitString(aString, delimiter)
set retVal to {}
set prevDelimiter to AppleScript's text item delimiters
log delimiter
set AppleScript's text item delimiters to {delimiter}
set retVal to every text item of aString
set AppleScript's text item delimiters to prevDelimiter
return retVal
end splitString
I go from there to create a BBEdit file.
Any questions, feel free to ask.
Cheers