2
2

More than 5 years have passed since last update.

Google Drive にアップしたテキストファイルの見栄えをよくする (2.フォルダアクションの設定)

Last updated at Posted at 2013-12-15

前回の続きです。

Google Drive のフォルダに対して フォルダアクションをしかけます。

フォルダアクションとは


フォルダアクションは AppleScript による一種のシステムの監視機能であり、ユーザがフォルダに対して行った変更をきっかけに、あらかじめ定めておいた処理を開始させることができます。

有名どころだと「iTunes ライブラリに自動的に追加」の機能など。
Apple サポート:「iTunes に自動的に追加」フォルダについて

フォルダアクションの追加


AppleScriptEditor で AppleScript を書いてシステムに登録する、という方法もありますが、Automator で作成するのがてっとり早く、後々の管理も楽です。

  1. Automator を起動
  2. ワークフローの選択で、「フォルダアクション」を選択して決定
  3. "フォルダアクション"の実行場所を割り当てる。任意のGoogle Drive 上のフォルダ(テキストファイルを配置しようとしているフォルダ)を割り当てましょう
  4. "AppleScript を実行" を右ペインにドラッグ & ドロップ
  5. AppleScript を編集して保存

作成する AppleScript はこんな感じです。


on run {input, parameters}

    try
        set addedItemPath to (input's POSIX path)
        set ourSh to "echo " & addedItemPath
        set str2 to do shell script ourSh
        set str1 to "item added.
"
        display dialog str1 & str2

        do shell script "cupsfilter " & addedItemPath & " > out.pdf"
        delay 1

    on error
        display dialog "can't get file path."
    end try

end run

指定したフォルダにファイルを追加すると、cupsfilter コマンドで pdf 変換を試みます。要は Unixコマンドなのですが、これを Applescript から使うために do shell scriptしています。

Screen shot 2013-12-01 at 22.52.40.png

使わないフォルダアクションを削除する


以下のアプリケーションを使って、フォルダとスクリプトの紐付けを解除したり、スクリプトを削除することができます。

/System/Library/CoreServices/Folder Actions Setup.app

uploading Screen shot 2013-12-01 at 22.52.40.png...

参考


Automatorでフォルダアクションをつくる記事(画面キャプチャあり)
Evernoteにファイルを保存するフォルダアクションの作り方

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2