text
stringlengths
0
15.7k
source
stringlengths
6
112
error "Download failed."
Pinboard.scpt
else if theXML contains "503 Service Temporarily Unavailable" then
Pinboard.scpt
error "503 Service Temporarily Unavailable"
Pinboard.scpt
logMessage("theXML:", theXML, 3)
Pinboard.scpt
set x to make new XML data with data theXML
Pinboard.scpt
set theElements to XML elements of (XML element 1 of x) -- <posts>
Pinboard.scpt
set theElementCount to length of theElements
Pinboard.scpt
my logMessage("Elements to process from XML:", theElementCount as string, 1)
Pinboard.scpt
if (theElementCount < 1) then
Pinboard.scpt
error "Pinboard says it found no new bookmarks."
Pinboard.scpt
show progress indicator "Importing " & theElementCount & " bookmarks from Pinboard (" & pUser & ") …" steps (theElementCount) with cancel button
Pinboard.scpt
set importedPosts to 0
Pinboard.scpt
repeat with theSteps from theElementCount to 1 by -1
Pinboard.scpt
set theElement to item theSteps of theElements
Pinboard.scpt
set theUrl to (value of XML attribute named "href" of theElement) as string
Pinboard.scpt
if not (exists record with URL theUrl) then
Pinboard.scpt
step progress indicator theUrl
Pinboard.scpt
my logMessage(theUrl, "…", 3)
Pinboard.scpt
set theName to (value of XML attribute named "description" of theElement) as string
Pinboard.scpt
set theTag to (value of XML attribute named "tag" of theElement) as string
Pinboard.scpt
set theComment to (value of XML attribute named "extended" of theElement) as string
Pinboard.scpt
set theDate to (value of XML attribute named "time" of theElement) as string
Pinboard.scpt
set theExtension to ""
Pinboard.scpt
set _url to (current application's |NSURL|'s URLWithString:theUrl)
Pinboard.scpt
set theExtension to _url's pathExtension as string
Pinboard.scpt
tell me to set the theExtension to do shell script "echo " & quoted form of (theExtension) & " | tr A-Z a-z"
Pinboard.scpt
set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, " "}
Pinboard.scpt
set theTags to {}
Pinboard.scpt
set theTags to (text items of theTag)
Pinboard.scpt
if (theExtension is in {"pdf", "jpg", "jpeg", "png", "zip", "rtf", "csv", "dmg", "doc", "docx", "ppt", "pptx", "xls", "xlsx", "key", "pages", "key", "numbers"}) then
Pinboard.scpt
set theRecord to create web document from theUrl in theGroup
Pinboard.scpt
else if (theExtension is in {"zip", "dmg", "exe", "tar", "gz"}) then
Pinboard.scpt
set theRecord to create record with {type:bookmark, rich text:theComment} in theGroup
Pinboard.scpt
if (importStrategy is "create web document") then
Pinboard.scpt
else if (importStrategy is "create PDF document") then
Pinboard.scpt
set theRecord to create PDF document from theUrl in theGroup with pagination
Pinboard.scpt
else if (importStrategy is "create formatted note") then
Pinboard.scpt
set theRecord to create formatted note from theUrl in theGroup
Pinboard.scpt
else if (importStrategy is "decluttered") then
Pinboard.scpt
set theMarkDownUrl to "http://heckyesmarkdown.com/go/?read=1&md=1&u=" & (my encodeText:theUrl)
Pinboard.scpt
set theContent to download markup from theMarkDownUrl
Pinboard.scpt
if (length of theContent < 400) then
Pinboard.scpt
set theRecord to create record with {type:markdown, content:theContent} in theGroup
Pinboard.scpt
else if (importStrategy is "create Markdown") then
Pinboard.scpt
set theRecord to create Markdown from theUrl in theGroup
Pinboard.scpt
else if (importStrategy is "create record") then
Pinboard.scpt
set the name of theRecord to theName
Pinboard.scpt
set the tags of theRecord to theTags
Pinboard.scpt
set the URL of theRecord to theUrl
Pinboard.scpt
set the comment of theRecord to theComment
Pinboard.scpt
set the date of theRecord to (my dateFromRfc3339String:theDate)
Pinboard.scpt
set theGroup's comment to theDate
Pinboard.scpt
set importedPosts to importedPosts + 1
Pinboard.scpt
my logMessage(theUrl, error_message, 0)
Pinboard.scpt
my logMessage(theUrl, "Skipped as duplicate", 3)
Pinboard.scpt
set thePercentage to theSteps / theElementCount
Pinboard.scpt
set thePercentage to round thePercentage * 100 rounding down
Pinboard.scpt
my logMessage(theUrl, (thePercentage as string) & "% of " & theElementCount, 4) -- I am lazy. Log level 4 is a magic number. When you set scriptDebugging to true, this info will be logged to AppleScript's log but will never show up in DT.
Pinboard.scpt
if cancelled progress then exit repeat
Pinboard.scpt
if silentMode is false then
Pinboard.scpt
display alert "Pinboard importer" message error_message as warning
Pinboard.scpt
my logMessage(error_number, error_message, 0)
Pinboard.scpt
if exists POSIX file "/System/Library/Sounds/Glass.aiff" then
Pinboard.scpt
do shell script "afplay /System/Library/Sounds/Glass.aiff"
Pinboard.scpt
display alert "Done importing." & return & return & "Processed bookmarks: " & theElementCount & return & "Skipped:" & (theElementCount - importedPosts) & return & "Imported: " & importedPosts
Pinboard.scpt
if silentMode is false and the error_number is not -128 then display alert "Pinboard importer" message error_message as warning
Pinboard.scpt
my logMessage(error_number, error_message, 4)
Pinboard.scpt
on rfc3339FromDate:aDate
Pinboard.scpt
theFormatter's setTimeZone:(current application's NSTimeZone's timeZoneWithAbbreviation:"GMT") -- skip for local time
Pinboard.scpt
theFormatter's setDateFormat:"yyyy'-'MM'-'dd'T'HH':'mm':'ssXXX"
Pinboard.scpt
end rfc3339FromDate:
Pinboard.scpt
on dateFromRfc3339String:theString
Pinboard.scpt
return (theFormatter's dateFromString:theString) as date
Pinboard.scpt
end dateFromRfc3339String:
Pinboard.scpt
on encodeText:theText
Pinboard.scpt
set theString to stringWithString_(theText) of NSString of current application
Pinboard.scpt
set theEncoding to NSUTF8StringEncoding of current application
Pinboard.scpt
set theAdjustedString to stringByAddingPercentEscapesUsingEncoding_(theEncoding) of theString
Pinboard.scpt
return (theAdjustedString as string)
Pinboard.scpt
end encodeText:
Pinboard.scpt
on logMessage(logResource, logInfo, logLevel)
Pinboard.scpt
if ((logLevel ≥ logVerbosity) and (logLevel < 4)) then
Pinboard.scpt
log message logResource info (logInfo as String)
Pinboard.scpt
if (scriptDebugging) then
Pinboard.scpt
log logInfo & ": " & logResource
Pinboard.scpt
set MY_USERNAME to "username"
HUJA.applescript
set MY_PASSWORD to "password"
HUJA.applescript
set PROXY_SERVER to ".ezp-prod1.hul.harvard.edu"
HUJA.applescript
set loginAnyway to false
HUJA.applescript
tell application "Safari" to set origURL to URL of front document as string
HUJA.applescript
if origURL does not contain "harvard" then
HUJA.applescript
set URLparts to text items of origURL
HUJA.applescript
set item 3 of URLparts to item 3 of URLparts & PROXY_SERVER
HUJA.applescript
set newURL to URLparts as string
HUJA.applescript
tell application "Safari" to set the URL of the front document to newURL
HUJA.applescript
set loginAnyway to true
HUJA.applescript
tell application process "Safari"
HUJA.applescript
set loading to (get properties of button 1 of text field 1 of splitter group 1 of group 2 of tool bar 1 of window 1)
HUJA.applescript
if (accessibility description of loading) does not contain "stop" then exit repeat
HUJA.applescript
tell application "Safari" to set latestURL to URL of front document as string
HUJA.applescript