以下の内容はhttps://wineroses.hatenablog.com/entry/2024/09/09/220637より取得しました。


Obsidian:選択範囲を転送するスクリプト

URLスキームがあれば。

Twitter.md

選択範囲が消えるので修正しました。

下記スクリプトをTemplaterに登録してお使いください。

<%*
url = "twitter://post?message="

s = tp.file.selection()
if(s){
  tp.file.cursor_append(s)
}else{
  e = app.workspace.activeLeaf.view.editor
  p = e.getCursor().line
  s = e.getLine(p)
  if(!s) s = tp.file.content
}
open(`${url}${encodeURIComponent(s)}`)
%>

使い方

  • 範囲選択しているときは、その部分だけを転送。
  • 選択してなければカーソル行を転送。
  • カーソル行が空行なら全文転送になります。

万全の三段構えになってます。

ArcSearch

変数urlにURLスキームを入れれば他のアプリに転送できます。

たとえばArc Searchの場合は:

<%*
url = "arcmobile2://search?query="

s = tp.file.selection()
if(s){
  tp.file.cursor_append(s)
}else{
  e = app.workspace.activeLeaf.view.editor
  p = e.getCursor().line
  s = e.getLine(p)
  if(!s) s = tp.file.content
}
open(`${url}${encodeURIComponent(s)}`)
%>

質問を書き込んで生成AIに答えてもらえます。

ArcClipを使うと、Browse for Meの結果をObsidianに転送できます。

まとめ

BearでもDraftsでも。 このスクリプト、応用範囲が広い。

今日のカレー沢先生

創作の道は厳しい。 「相手の気持ちに泥を塗ってはいけない」は名言。

ブラケットも消す

内部リンクのブラケットを転送分から消すには:

<%*
url = "twitter://post?message="

s = tp.file.selection()
if(s){
  tp.file.cursor_append(s)
}else{
  e = app.workspace.activeLeaf.view.editor
  p = e.getCursor().line
  s = e.getLine(p)
  if(!s) s = tp.file.content
}
s = s.replace(/!?\[\[(.+?)\]\]/mg, "$1")
open(`${url}${encodeURIComponent(s)}`)
%>

転送前の置換でいけませんか?




以上の内容はhttps://wineroses.hatenablog.com/entry/2024/09/09/220637より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14