2017-08-16 5 views
1

これは私の最初のアプリスクリプトです。私は という名前のスクリプトを起動するためにautomatorを使用します。新しいファイルをフォルダにドロップします(フォルダアクション)。 AutomatorのでAppleScriptでテキストエディットでファイルを開いてpdfとしてエクスポート

私は2アクション持っている: 1-指定のFinder項目を取得します 2 - アップルスクリプト

をしかし、私はそれを実行していることはできません。ファイルを開いた後、警告なしでスクリプトが停止します。ここで

はスクリプトです:

on run {input, parameters} 

tell application "TextEdit" to activate 

repeat with theFile in input 

    set theFilePath to theFile as alias 

    tell application "TextEdit" to open theFilePath 

    tell application "System Events" 
     tell process "TextEdit" 
      set foremost to true 
      click menu item "Export as PDF..." of menu "File" of menu bar 1 
      click button "Save" 
      click menu item "Close" of menu "File" of menu bar 1 
     end tell 
    end tell 

end repeat 

return input 
end run 

誰もがこの上で私を助けることができますか?

テキストエディットを使用して、指定したフォルダ内のすべてのファイルをpdfにエクスポートしたいだけです。

おかげ

答えて

0
on adding folder items to this_folder after receiving these_items 
    repeat with i from 1 to number of items in these_items 
     set this_item to item i of these_items 
     tell application "TextEdit" 
      activate 
      open this_item 
      delay 1 
      tell application "System Events" 
       click menu item "Export as PDF…" of menu 1 of menu bar item "File" of menu bar 1 of application process "TextEdit" 
       delay 1 
       key code 36 
       delay 1 
       key code 13 using command down 
      end tell 
     end tell 
    end repeat 
end adding folder items to 

この代替バージョンは.PDFにファイルを変換した後TextEditアプリケーションを終了します。 TextEditが既に実行されている場合は、開いている文書を保存せずに終了するように設定しているので、このバージョンを使用するように注意してください。

on adding folder items to this_folder after receiving these_items 
    repeat with i from 1 to number of items in these_items 
     set this_item to item i of these_items 
     tell application "TextEdit" 
      activate 
      open this_item 
      delay 1 
      tell application "System Events" 
       click menu item "Export as PDF…" of menu 1 of menu bar item "File" of menu bar 1 of application process "TextEdit" 
       delay 1 
       key code 36 
       delay 1 
       key code 13 using command down 
      end tell 
     end tell 
    end repeat 
    ignoring application responses 
     tell application "TextEdit" to quit without saving 
    end ignoring 
end adding folder items to 

あなたが/のユーザーに「Convert_To_PDF.scpt」としてスクリプトエディタで、この次のAppleScriptを保存する場合は/ユーザー名/ライブラリ/ワークフロー/アプリケーション/フォルダアクションフォルダを挿入します。 Automatorをまったく使用する必要はありません。

:あなたは、「フォルダアクション設定」を選択した後、あなたがこれを見ます

enter image description here

:あなたは、単に+コントロールあなたの「ホットフォルダ」として、あなたが望む任意のフォルダをクリックする必要があり、あなたはこれを見ますenter image description here

AppleScriptを/ Library/Workflows/Applications/Folder Actionsフォルダに保存したため、+記号をクリックしてフォルダアクションのフォルダにスクリプトを追加すると、自動的に選択するスクリプト

enter image description here

enter image description here

あなたはAppleScriptのコード内の遅延設定を少し調整する必要があります。いずれにせよ、これはSierraの最新バージョンで私のために機能します。

+0

「キーコード36」と「コマンドダウンを使用するキーコード13」は何の意味ですか? – t4ncr3d3

+0

「キーコード36」はリターンキーを押し、「キーコード13はコマンドダウンを使用しています」はコマンドを押すことであり、「w」はウィンドウまたはドキュメントを閉じるためのショートカットです – wch1zpink

関連する問題