AppleScript アップルスクリプト 質問、発表 6

このエントリーをはてなブックマークに追加
407名称未設定
Applescriptの話になってきたので
「Mac OS Xのテキストエディタ総合 Part12」から移動してきました

--CotEditorでファイルを開いて文末に日時を挿入
--ファイルパスの例"/Users/ユーザー名/Desktop/ファイル名.txt"
set filePath to "ファイルパス" as POSIX file

--上記ファイルパスのファイルをCotEditorで開く
--(CotEditor.appがApplicationsフォルダの直下にある場合を想定)
tell application "Finder"
open filePath using file "CotEditor" of folder "Applications" of startup disk
end tell

tell application "CotEditor"
activate
tell front document
-- カーソルをドキュメントの末尾に移動
set docLen to length
set range of selection to {docLen, 0}
--末尾に日時を挿入
set contents of selection to return & return & return & return & "---" & (current date) & "---"
--日時挿入した行の2行上にカーソルを移動
set theRange to range of selection
scroll to caret
set item 1 of theRange to (item 1 of theRange) + 2
set item 2 of theRange to 0
set range of selection to theRange
end tell
end tell
408名称未設定:2014/12/10(水) 23:06:29.19 ID:8lxhxVtu0
>>407の補足

これならCotEditor起動時に新規ファイルは開かないようです

あと、これをアプリケーション形式で保存しても
少なくともうちのOS10.6.8の環境では問題なく動作していますねぇ

開きたいテキストファイルをAppleScriptエディタのウインドウに
ドラッグするとフルパスが入るので、それを使えば
アプリケーション形式で保存したスクリプトをどこに置こうが
大丈夫かと思いますけども

アプリを「実行専用」にしないで書き出していれば、
書き出したアプリを右クリックしてパッケージを表示し、
「Contents/Resources/Scripts/main.scpt」
をダブルクリックすればファイルパスを書き換えることができますよ