Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AlfredのワークフローでScrapboxを検索する
# Originally created by Yuta Yamamoto <https://github.com/tuki0918/alfred-scrapbox-listview>
file = "/tmp/#{ENV['projectId']}-scrapbox.json"
if !File.exist?(file) or File.mtime(file) < (Time.now - 3*3600)
`/usr/bin/curl -H "Cookie: connect.sid=#{ENV['token']}" -o #{file} -s "https://scrapbox.io/api/pages/#{ENV['projectId']}?limit=1000&sort=accessed"`
end
q = `echo "{query}" | /usr/local/bin/nkf -w --ic=utf8-mac`
q.strip!
items = `/bin/cat #{file} | /usr/local/bin/jq -c '[ .pages[] | select(.title | test("#{q}";"i")) |\
{ \
"uid":.id \
,"title":.title \
,"subtitle": ("description: " + (.descriptions | join(" / ")) + "...") \
,"arg":.title
} \
]'`
print '{"items":'
print items.strip
print '}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment