text
stringlengths 0
15.7k
| source
stringlengths 6
112
|
---|---|
activate "OmniFocus"
|
Open Inbox.applescript
|
on convertASToJSON:someASThing saveTo:posixPath
|
get-tbr.applescript
|
set {theData, theError} to current application's NSJSONSerialization's dataWithJSONObject:someASThing options:0 |error|:(reference)
|
get-tbr.applescript
|
if posixPath is missing value then -- return string
|
get-tbr.applescript
|
set someString to current application's NSString's alloc()'s initWithData:theData encoding:(current application's NSUTF8StringEncoding)
|
get-tbr.applescript
|
set theResult to theData's writeToFile:posixPath atomically:true
|
get-tbr.applescript
|
return theResult as boolean -- returns false if save failed
|
get-tbr.applescript
|
end convertASToJSON:saveTo:
|
get-tbr.applescript
|
on page_down()
|
get-tbr.applescript
|
key code 119
|
get-tbr.applescript
|
end page_down
|
get-tbr.applescript
|
on get_tbr_count()
|
get-tbr.applescript
|
make new document with properties {URL:"https://app.thestorygraph.com/to-read/andregarzia"}
|
get-tbr.applescript
|
my page_down()
|
get-tbr.applescript
|
set paneCount to do JavaScript "panes = document.querySelectorAll('.book-pane').length" in document 1 -- fill data
|
get-tbr.applescript
|
log "total books in tbr: " & paneCount
|
get-tbr.applescript
|
return paneCount
|
get-tbr.applescript
|
end get_tbr_count
|
get-tbr.applescript
|
on get_current_isbn(bookId)
|
get-tbr.applescript
|
make new document with properties {URL:"https://app.thestorygraph.com/books/" & bookId & "/editions"}
|
get-tbr.applescript
|
set isbn to do JavaScript "isbn = document.evaluate(\"//span[text()='ISBN:']\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.parentElement.innerText.replace('ISBN: ','')" in document 1
|
get-tbr.applescript
|
return isbn
|
get-tbr.applescript
|
end get_current_isbn
|
get-tbr.applescript
|
on write_tbr_html(tbr)
|
get-tbr.applescript
|
log "Writing tbr.html.pmd"
|
get-tbr.applescript
|
set the_file to "/Users/me/site/tbr.poly.pmd"
|
get-tbr.applescript
|
log "opening file"
|
get-tbr.applescript
|
set dataStream to open for access the_file with write permission
|
get-tbr.applescript
|
set eof of dataStream to 0
|
get-tbr.applescript
|
write ("#lang pollen" & linefeed & linefeed) to dataStream starting at eof as «class utf8»
|
get-tbr.applescript
|
write ("◊(define-meta title " & quote & "TBR List" & quote & ")" & linefeed & linefeed) to dataStream starting at eof as «class utf8»
|
get-tbr.applescript
|
write (("_Generated on " & (current date) as string) & "_" & linefeed & linefeed) to dataStream as «class utf8»
|
get-tbr.applescript
|
repeat with book in tbr
|
get-tbr.applescript
|
write ("### [" & the title of book & "](https://app.thestorygraph.com/books/" & the storygraphBookId of book & ")" & linefeed) to dataStream as «class utf8»
|
get-tbr.applescript
|
write ("* **Author:** [" & the author of book & "](https://app.thestorygraph.com/authors/" & the storygraphAuthorId of book & ")" & linefeed) to dataStream as «class utf8»
|
get-tbr.applescript
|
if the series of book is not missing value then
|
get-tbr.applescript
|
write ("* **Series:** " & the series of book & linefeed) to dataStream as «class utf8»
|
get-tbr.applescript
|
if the isbn of book is not "None" then
|
get-tbr.applescript
|
write ("* **ISBN:** " & the isbn of book & linefeed) to dataStream as «class utf8»
|
get-tbr.applescript
|
if the owned of book is true then
|
get-tbr.applescript
|
write ("* **😻 YOU ALREADY HAVE THIS BOOK 📚**" & linefeed) to dataStream as «class utf8»
|
get-tbr.applescript
|
write linefeed to dataStream as «class utf8»
|
get-tbr.applescript
|
log "- tbr " & the title of book
|
get-tbr.applescript
|
close access dataStream
|
get-tbr.applescript
|
on error errmsg number num
|
get-tbr.applescript
|
log errmsg
|
get-tbr.applescript
|
close access file the_file
|
get-tbr.applescript
|
end write_tbr_html
|
get-tbr.applescript
|
set tbrCount to my get_tbr_count()
|
get-tbr.applescript
|
set tbr to {}
|
get-tbr.applescript
|
repeat with x from 1 to tbrCount
|
get-tbr.applescript
|
set mySeries to do JavaScript "series = document.querySelector(':nth-child(" & x & " of .book-pane) div.book-title-author-and-series > p > a').innerText" in document 1
|
get-tbr.applescript
|
set myTitle to do JavaScript "title = document.querySelector(':nth-child(" & x & " of .book-pane) div.book-title-author-and-series > h3 > a').innerText" in document 1
|
get-tbr.applescript
|
set myBookId to do JavaScript "bookid = document.querySelector(':nth-child(" & x & " of .book-pane)').getAttribute('data-book-id')" in document 1
|
get-tbr.applescript
|
set myAuthorId to do JavaScript "authorId = document.querySelector(':nth-child(" & x & " of .book-pane)').getAttribute('data-author-ids').substring(0,36)" in document 1
|
get-tbr.applescript
|
set myOwnedLocation to do JavaScript "bookOwned = document.querySelector(':nth-child(" & x & " of .book-pane)').innerText.indexOf('Mark as owned')" in document 1
|
get-tbr.applescript
|
if myOwnedLocation is -1 then
|
get-tbr.applescript
|
set myOwned to true
|
get-tbr.applescript
|
set myOwned to false
|
get-tbr.applescript
|
set myISBN to my get_current_isbn(myBookId)
|
get-tbr.applescript
|
log myTitle
|
get-tbr.applescript
|
set myAuthor to do JavaScript "author = document.querySelector(':nth-child(" & x & " of .book-pane) div.book-title-author-and-series > :nth-child(2 of p)').innerText" in document 1
|
get-tbr.applescript
|
copy {title:myTitle, series:mySeries, author:myAuthor, storygraphBookId:myBookId, storygraphAuthorId:myAuthorId, isbn:myISBN, owned:myOwned} to end of tbr
|
get-tbr.applescript
|
copy {title:myTitle, author:mySeries, series:missing value, storygraphBookId:myBookId, storygraphAuthorId:myAuthorId, isbn:myISBN, owned:myOwned} to end of tbr
|
get-tbr.applescript
|
my convertASToJSON:tbr saveTo:("/Users/me/site/tbr.json")
|
get-tbr.applescript
|
my write_tbr_html(tbr)
|
get-tbr.applescript
|
log "Ended"
|
get-tbr.applescript
|
display notification "TBR Ready"
|
get-tbr.applescript
|
on getParentFolder(thePath)
|
getParentFolder.scpt
|
set parent_folder to text items of (thePath as text)
|
getParentFolder.scpt
|
set parent_folder to (reverse of parent_folder)
|
getParentFolder.scpt
|
set the_folder to item 2 of parent_folder
|
getParentFolder.scpt
|
return the_folder
|
getParentFolder.scpt
|
end getParentFolder
|
getParentFolder.scpt
|
set uname to name of home as text
|
qs-select-last-download.applescript
|
set dlpath to "/Users/" & uname & "/Downloads"
|
qs-select-last-download.applescript
|
set lastfn to do shell script "ls -tU " & dlpath & " | sed -e 's/\\ /\\%20/g' | head -1"
|
qs-select-last-download.applescript
|
set lastfn_url to "file://" & dlpath & "/" & lastfn
|
qs-select-last-download.applescript
|
tell application "Quicksilver"
|
qs-select-last-download.applescript
|
set selection to lastfn_url
|
qs-select-last-download.applescript
|
property NSCaseInsensitiveSearch : a reference to 1
|
Open and Complete.applescript
|
property NSRegularExpressionSearch : a reference to 1024
|
Open and Complete.applescript
|
set sel to selectedItems() of O
|
Open and Complete.applescript
|
repeat with _sel in sel
|
Open and Complete.applescript
|
repeat with paragraphCount from 1 to (count (paragraphs of note of _sel))
|
Open and Complete.applescript
|
set _paragraph to ((NSString's stringWithString:(paragraph paragraphCount of note of _sel))'s stringByTrimmingCharactersInSet:(NSCharacterSet's whitespaceAndNewlineCharacterSet())) as text
|
Open and Complete.applescript
|
if _paragraph starts with "Script:" then
|
Open and Complete.applescript
|
set shellScript to text 9 thru -1 of _paragraph
|
Open and Complete.applescript
|
set shellProgram to text item 1 of shellScript
|
Open and Complete.applescript
|
set shellArguments to (text items 2 thru -1 of shellScript as text)
|
Open and Complete.applescript
|
set finalShellArguments to (NSString's stringWithString:shellArguments)
|
Open and Complete.applescript
|
set shell to (finalShellArguments's stringByReplacingOccurrencesOfString:"~" withString:(POSIX path of (path to home folder)) options:NSCaseInsensitiveSearch range:{0, finalShellArguments's |length|()}) as text
|
Open and Complete.applescript
|
do shell script shellProgram & " " & quoted form of shell
|
Open and Complete.applescript
|
else if _paragraph starts with "Command:" then
|
Open and Complete.applescript
|
do shell script text 10 through -1 of _paragraph
|
Open and Complete.applescript
|
else if _paragraph contains "://" then
|
Open and Complete.applescript
|
do shell script "open " & quoted form of _paragraph
|
Open and Complete.applescript
|
log "Probably an iOS link"
|
Open and Complete.applescript
|
else if _paragraph starts with "App:" then
|
Open and Complete.applescript
|
set target to "-a " & quoted form of (text 6 thru -1 of _paragraph)
|
Open and Complete.applescript
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.