単純な Web フォームへの大量のデータ入力を必要とするソフトウェアを使用せざるを得ないため、入力としてテキスト ファイルを取得し、内容をキーストロークで Safari に出力するように AppleScript を設計しました。 Web フォームの次のフィールドに進むために使用されます。テキストファイルを読みやすくするために、テキストファイルの改行をタブとして扱うことができるように、文字列の置換を行っています。
クリップボードからキーストロークすることでこれを合理化したいのですが、これは機能しますが、文字列の置換が本来の方法で行われておらず、その理由を特定できません。この時点での私の回避策は、コピーする前に改行をタブで手動で検索/置換することですが、基本的にはファイルを保存してスクリプトをポイントするのと同じくらい遅くなります。
tell application "Safari"
activate
end tell
set sourceString to (the clipboard) as text
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "\n"
set the lineList to every text item of sourceString
set AppleScript's text item delimiters to "\t"
set keystrokeString to the lineList as string
set AppleScript's text item delimiters to ASTID
tell application "System Events"
keystroke keystrokeString as text
end tell
\t
\n
これを AppleScript Editor に入れると、不可視にコンパイルされます。次を使用してファイルから読み取ると、文字列編集 (中間) 部分が宣伝どおりに機能します。
set theFile to (choose file with prompt "Select a file to read:" of type {"txt"})
open for access theFile
set fileContents to (read theFile)
close access theFile
クリップボードからテキストを取得したときに文字列の置換が機能しない理由はありますか?