20260622

指定のファイルタイプの場合のみ指定のアプリケーションで開く

指定のファイルタイプの場合のみ指定のアプリケーションで開く

NOTE記事一覧ですnote.com
 

【Safari・FireFox用Script Editorで開く】 |

指定ファイルなら指定のアプリケーションで開く.scpt.scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003use AppleScript version "2.8"
004use scripting additions
005
006on 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
016end run
017
018#ドロップレット形式
019on 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
042end open
043
044
045on 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
051end doOpenFile
AppleScriptで生成しました