:
1)GUIスクリプトを使用する方法:これはあなたがし始めてきたものです。ユーザーのようなキーボードイベントをシミュレートします。主に3つの理由で推奨されていません。通常は遅いです(システムオープンウィンドウの時間を残して終了するには遅延を追加する必要があります)。スクリプト中に、ユーザーが誤ってキー/マウスを押すと、スクリプトは失敗します。最後に、アプリケーションのユーザーインターフェイスにはほとんど依存しません。エディタ(ここではTextEditを使用するApple)がショートカットキーのように変更された場合、スクリプトはもう機能しません。
それでも、この方法を使用したい場合は、ここではそれを行うスクリプトがあります。私がしたようにコメントを追加することをお勧めします(キーコード8が 'c'であることを覚えておく方法)!保存するパスを選択するためのいくつかのオプションを追加しました(ホームフォルダに移動し、特別なパスを入力してください...)。使用するかどうかまで:
tell application "TextEdit"
activate
tell application "System Events"
key code 126 using command down -- command up (cursor at start)
key code 125 using shift down -- shift down (select 1st line)
keystroke "c" using command down -- command C (copy)
keystroke "s" using command down -- open save dialog
delay 0.5 -- to let save as dialog time to open
keystroke "v" using command down -- paste the title from clipboard
-- other options
-- keystroke "h" using {command down, shift down} -- go home directory
delay 0.5
keystroke "g" using {command down, shift down} -- go to dialog
delay 0.5
keystroke "Desktop/Sample" -- path from Documents folder to Sample folder on Desktop
delay 0.5
keystroke return -- close the go to dialog
delay 0.5
keystroke return -- close the save as dialog
end tell
end tell
2)AppleScript命令を使用する方法。通常、はるかに短く、より洗練されたスクリプトであり、実行するのがはるかに高速であり、ユーザーは実行中にそれを壊すことができません。スクリプトは上記のスクリプトと同じことを行います:最初のテキスト行を選択し、そのタイトルの文書を保存します。 1行目はどこ保存するフォルダを定義しています
set myPath to (path to desktop folder) as string -- path where to save file
tell application "TextEdit"
activate
tell front document
set myTitle to first paragraph
set myTitle to text 1 thru -2 of myTitle -- to remove the return at end of paragraph
save in (myPath & myTitle)
end tell
end tell
私はそれが
だけの名前とパスを提供する命令「として保存」を使用できます願っています。 – pbell
名前はクリップボードにあります。私はこのように命名を自動化したい。 – Jimmbo