Showing posts with label AppleScript. Show all posts
Showing posts with label AppleScript. Show all posts

January 23, 2011

FinderからCotEditorでファイルを開くアプリ

FinderからCotEditorでファイルを開くアプリ。
OpenInCotEditor.zip
解凍してOpen in CotEditor.appをアプリケーションフォルダなどに置く。
でFinderのツールバーにドラッグアンドドロップ。
もちろんCotEditorがインストールされていること。

使い方はFinderで開きたいファイルを選択してアイコンをクリック。
複数のファイルでも開けます。

アイコンは勝手に使っていいのかわかんないからデフォルトのまま。



つくりかた


Open in TextMateを参考に。ていうか「TextMate」を「CotEditor」に変えただけ。

  1. Applications → UtilityからAppleScript Editorを開く。
  2. 新規作成。
  3. 以下のコードを入力。
    -- Opens the currently selected Finder files, or else the current Finder window, in CotEditor. Also handles dropped files and folders.
    
    -- By satomacoto 
    -- Based on http://henrik.nyh.se/2007/10/open-in-textmate-from-leopard-finder
    
    -- script was clicked
    on run
     tell application "Finder"
      if selection is {} then
       set finderSelection to folder of the front window as string
      else
       set finderSelection to selection as alias list
      end if
     end tell
     
     ce(finderSelection)
    end run
    
    -- script was drag-and-dropped onto
    on open (theList)
     ce(theList)
    end open
    
    -- open in CotEditor
    on ce(listOfAliases)
     tell application "CotEditor"
      open listOfAliases
      activate
     end tell
    end ce
  4. アプリケーションとして保存。

AppleScriptは便利だな。

January 25, 2010

CotEditorでLaTeXファイルをタイプセットするスクリプト

編集中のTeXファイルをDrag & Drop pTeXでタイプセットするスクリプト。texファイルはどこかに保存されている必要があります。デフォルトではpTeX.appは“アプリケーション”フォルダにインストールされているとします。pTeX.appのスクリプトを参考にしました。少し書き換えればportsなどでインストールしたpTeXにも対応できるかもしれません。

ダウンロード

TeX2PDF.applescript
TeX2PDFwBibTeX.applescript (jBibTeX)
https://gist.github.com/1601133


インストール

スクリプトフォルダ
~/Library/Application Support/CotEditor/ScriptMenu/
以下のどこかに置きます。メニューバーのスクリプトメニュー(ヘルプの左)から“スクリプトフォルダを開く”ことができます。Finderであるフォルダに移動するためには command + shift + g が便利です。

使い方

* インストールしたらメニューバーのスクリプトメニュー(ヘルプの左)から“スクリプトメニューを更新”。ちゃんとインストールされていたらTeX2PDFというメニューが表示されているはず。TeXファイルを保存したら、そのメニューをポチッと。

* デフォルトではファイル名をTeX2PDF.@~p.applescriptとしたら、ショートカットは、
command + option + p
ショートカットの変更の仕方は ~/Library/Application Support/CotEditor/ScriptMenu/_aboutScriptFolder.rtf に載っています。

たとえばTeXShopのように command + t にショートカットを当てたかったら、ファイル名を[email protected]とします。ただしこの場合はFontパネルのショートカットとバッティングしてしまうのでCotEditorのKey Bindingの設定でShow Fontsのショートカットをつぶしましょう。

* TeXファイルが保存されていないとタイプセットできないので、 command + s → command + option + p というコンボで使うといいと思います。

注意

ターミナルの Preferences > Setting > Shell > When the shell exits: で Close if the shell exited cleanly を選んでおかないとウィンドウが開きっぱなしになってしまうので鬱陶しいです。

雑感

CotEditorDrag & Drop pTeXもすごくいい!

追記(2010/8/29)

jBibTeXも含めたものを追加しました。

追記(2010/9/14)

TeX2PDFwBibTeX.applescriptのバグを取り除きました。

追記 (2011/1/25)

gs: command not foundなんてエラーが出るときは小川さんのページでESP Ghostscriptをダウンロードしてインストール。