2013年9月21日土曜日

Mac OSXで右クリックで新規ファイルを作成



f:id:j_wort:20121223023928p:image:w360:left

Launchpadから[その他]のグループアイコンの中にAutomatorがいるので起動。
f:id:j_wort:20121223023929p:image
サービスをクリックして[選択]ボタンを押す。

f:id:j_wort:20121223023930p:image

f:id:j_wort:20121223054313p:image:left
デフォルトだとこうなっているのでクリックして対象を
[ファイルまたはフォルダ]に変更


f:id:j_wort:20121223023950p:image

f:id:j_wort:20121223050204p:image



f:id:j_wort:20121223023951p:image


property defaultFileName : "newTextFile"

on run {input, parameters}

try
tell application "Finder" to set the sourceFolder to (folder of the front window) as alias
on error
-- no open folder windows
set the sourceFolder to path to desktop folder as alias
end try

set flagFileExists to true
set indexFile to ""

repeat while flagFileExists
set indexFile to (indexFile + 1)
tell application "Finder"
set flagFileExists to (exists file (defaultFileName & indexFile & ".txt") in sourceFolder)
end tell
end repeat

try
tell me
activate
set newFileName to text returned of (display dialog "Enter new file name" default answer "" & defaultFileName & indexFile)
end tell
if newFileName is not equal to "" & defaultFileName & indexFile then
set defaultFileName to newFileName
end if
set newFile to "" & sourceFolder & newFileName & ".txt"

if not flagFileExists then
set touchScript to "touch " & quoted form of (POSIX path of newFile)
set openScript to "open " & quoted form of (POSIX path of newFile)
do shell script touchScript
do shell script openScript
else
display dialog "File already exists"
end if
end try
return input
end run




f:id:j_wort:20121223023952p:image
ハンマーボタンを押してコンパイルしましょう。
f:id:j_wort:20121223023953p:image
色が変わります。


以上!


f:id:j_wort:20121223050205p:image


あとは
f:id:j_wort:20121223023945p:image:left
[ファイル]ー[保存]
で今作ったスクリプトを保存です。
ファイル名は[ファイル作成]とかで可。






フォルダ名のところで右クリックしたところ
f:id:j_wort:20121223023954p:image
メニューが出て [ファイル作成] が出ました。

f:id:j_wort:20121223023955p:image

FinderCover Flow表示だとフォルダが見えないから、
ファイルの上で右クリックすれば新規作成できますね。
f:id:j_wort:20121223050206p:image

いじょ。
f:id:j_wort:20121223031106p:image:small:left
対象OSMac OS X 10.8.X (Mountain Lion)

0 件のコメント: