
指定のファイルタイプの場合のみ指定のアプリケーションで開く
【Safari・FireFox用Script Editorで開く】 |
| ソース | |
|---|---|
| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | use AppleScript version "2.8" |
| 004 | use scripting additions |
| 005 | |
| 006 | on run |
| 007 | |
| 008 | tell application "Finder" |
| 009 | set listAliasFilePath to selection as alias list |
| 010 | end tell |
| 011 | |
| 012 | |
| 013 | set boolDone to (open listAliasFilePath) as boolean |
| 014 | |
| 015 | return boolDone |
| 016 | end run |
| 017 | |
| 018 | #ドロップレット形式 |
| 019 | on open listAliasFilePath |
| 020 | |
| 021 | set listUTI to {"public.plain-text", "com.apple.applescript.text", "public.html", "net.daringfireball.markdown"} as list |
| 022 | |
| 023 | repeat with aliasFilePath in listAliasFilePath |
| 024 | set aliasFilePath to aliasFilePath as alias |
| 025 | #ドロップレットの場合、ユーザーが、意図しないファイルを投げることもあるので |
| 026 | #UTIで対象のファイルを限定させて、対象外のファイルでは何もしないようにする |
| 027 | set recordInfoFor to (info for aliasFilePath) as record |
| 028 | set boolIsDir to (folder of recordInfoFor) as boolean |
| 029 | if boolIsDir is false then |
| 030 | set boolIsAlias to (alias of recordInfoFor) as boolean |
| 031 | if boolIsAlias is false then |
| 032 | set strUTI to (type identifier of recordInfoFor) as text |
| 033 | set boolContain to (strUTI contains strUTI) as boolean |
| 034 | if boolContain is true then |
| 035 | set boolDone to doOpenFile(aliasFilePath) |
| 036 | end if |
| 037 | end if |
| 038 | end if |
| 039 | end repeat |
| 040 | |
| 041 | return true |
| 042 | end open |
| 043 | |
| 044 | |
| 045 | on doOpenFile(argAliasFilePath) |
| 046 | set aliasFilePath to argAliasFilePath as alias |
| 047 | tell application id "com.apple.TextEdit" |
| 048 | open file aliasFilePath |
| 049 | end tell |
| 050 | return true |
| 051 | end doOpenFile |
| AppleScriptで生成しました | |
