![見出し画像](https://assets.st-note.com/production/uploads/images/122467377/rectangle_large_type_2_62e8277f6c2fef8d2552c8eb91893149.jpeg?width=1200)
Linuxでnoteの記事作成作業:スクリーンショットのファイル作成直後にクリップボードに画像をコピーするように修正
2023年11月23日09時26分28秒の記録_Linuxでnoteの記事作成作業 - YouTube https://www.youtube.com/watch?v=71rt7bXAiFQ
2023年11月23日13時07分17秒の記録_Linuxでnoteの記事作成作業(クリップボードに画像をコピー) - YouTube https://www.youtube.com/watch?v=LMezSjW2X9E
2023年11月23日09時03分11秒の記録_Linuxでnoteの記事作成作業 - YouTube https://www.youtube.com/watch?v=wG3C3J7t3QU
title = re.sub(r'(\n)+', ' ', title)
title = re.sub(r'( )+', ' ', title)
# ファイル名特殊文字のサニタイズ処理
title = title.replace(" "," ").replace("\\","\").replace("*","*").replace("?","?").replace('"',"”").replace("<","<").replace(">",">").replace("|","|").replace("/","/").replace('(',"(").replace(')',")").replace('.',"。").replace('=',"=").replace('\'',"’").replace('#',"#").replace('%', "%").replace('^',"^").replace(":",":").replace(';',";").replace('^',"^").replace('~',"〜").replace('[',"[").replace(']',"]")[:66]
tdate = now.strftime('%Y-%m-%d_%H%M%S_')
tdate = "/home/a66/sc/{tdate}{title}.jpg".format(tdate=tdate, title=title)
subprocess.run(["scrot","-s",tdate])
subprocess.run(["notify-send", title])
with open('/home/a66/tmp/jpg-title.txt', 'a') as f:
print(f'a_screenshot <<<=== {time}', file=f)
print(title, file=f)
print("", file=f)
print(title)
subprocess.run('xclip -selection clipboard -t image/png < {f}'.format(f=tdate), shell=True)
スクリーンショットのファイルを作成して、ファイルブラウザからnoteの記事の編集画面にドラッグ・アンド・ドロップをすると、クリップボードに変化はなく、その前に保存したページタイトルなどを貼り付けることができます。
javascript:var global=window;global.COPY_TO_CLIPBOARD=global.COPY_TO_CLIPBOARD||{};global.COPY_TO_CLIPBOARD.getUrlInfo=function(){var a=new String("- "+document.title);a.allReplace=function(a){var b=this,c;for(c in a)b=b.replace(new RegExp(c,"g"),a[c]);return b}.bind(a);return a.allReplace({":":"\uff1a","\\[":"\uff3b","\\]":"\uff3d"})+" "+document.URL}; global.COPY_TO_CLIPBOARD.copyToClipboard=function(){var a=document.createElement("textarea");a.textContent=this.getUrlInfo();var d=document.getElementsByTagName("body")[0];d.appendChild(a);a.select();var b=document.execCommand("copy");d.removeChild(a);return b};global.COPY_TO_CLIPBOARD.copyToClipboard();
ずいぶん前から使っているJavaScriptのコードですが、ブラウザの拡張機能ででキーボードの「t」キーに割り付けています。
クリップボードから画像を貼り付けると、ドラッグ・アンド・ドロップより処理に時間がかかるのですが、その間にページタイトルなどのテキストをクリップボードに保存することができるので、ファイルブラウザへのウィンドウの切り替えが必要なくなります。ただ、パソコンの処理能力の不足なのか、スクリーンショットが真っ白で作成に失敗することも10回に2回は起きています。