Skip to content

Instantly share code, notes, and snippets.

@kdmsnr
Last active September 3, 2021 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdmsnr/26775a503d630fc06f2c0050271fc9ed to your computer and use it in GitHub Desktop.
Save kdmsnr/26775a503d630fc06f2c0050271fc9ed to your computer and use it in GitHub Desktop.
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