AppleScript Script Editor

[Script Editor]選択範囲をコメントにする

#行頭のコメント

AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003# スクリプトメニュー用
004----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
005use AppleScript version "2.8"
006use framework "Foundation"
007use scripting additions
008
009#コメントの行頭接頭語
010set strPreFix to "#\t" as text
011
012#テキスト取得
013tell application "Script Editor"
014  tell front document
015    tell selection
016      set listRange to (character range) as list
017      set strGetText to contents as text
018    end tell
019  end tell
020end tell
021#エラー回避
022if strGetText is "" then
023  return "範囲を選択していません"
024end if
025#初期値
026set strOutputText to "" as text
027set strLineEndChar to "\r" as text
028#テキストをリストにして
029set strDelim to AppleScript's text item delimiters
030set AppleScript's text item delimiters to strLineEndChar
031set listSelectText to every text item of strGetText
032set AppleScript's text item delimiters to strDelim
033#リストの数
034set numCntList to (count of listSelectText) as integer
035#テキスト行だけ繰り返し
036repeat with itemNo from 1 to numCntList by 1
037  set strLineText to (item itemNo of listSelectText) as text
038  if itemNo = 1 then
039    #最初の行
040    set strOutputText to (strPreFix & strLineText & strLineEndChar) as text
041  else
042    #それ以外の行
043    set strOutputText to (strOutputText & strPreFix & strLineText & strLineEndChar) as text
044  end if
045end repeat
046
047#テキストを戻す
048tell application "Script Editor"
049  tell front document
050    tell selection
051      set contents to strOutputText as text
052    end tell
053  end tell
054end tell
AppleScriptで生成しました

(**)を使ったコメント
AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003# スクリプトメニュー用
004----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
005use AppleScript version "2.8"
006use framework "Foundation"
007use scripting additions
008
009#テキスト取得
010tell application "Script Editor"
011  tell front document
012    tell selection
013      set listRange to (character range) as list
014      set strGetText to contents as text
015    end tell
016  end tell
017end tell
018#エラー回避
019if strGetText is "" then
020  return "範囲を選択していません"
021end if
022
023#初期値
024set strOutputText to "" as text
025set strLineEndChar to "\r" as text
026#テキストをリストにして
027set strDelim to AppleScript's text item delimiters
028set AppleScript's text item delimiters to strLineEndChar
029set listSelectText to every text item of strGetText
030set AppleScript's text item delimiters to strDelim
031
032
033##コメントの始まり
034copy "(*" to beginning of listSelectText
035##コメントの終わり
036copy "*)" to end of listSelectText
037
038#リストの数
039set numCntList to (count of listSelectText) as integer
040
041#テキスト行だけ繰り返し
042repeat with itemNo from 1 to numCntList by 1
043  set strLineText to (item itemNo of listSelectText) as text
044  if itemNo = 1 then
045    #最初の行
046    set strOutputText to (strLineText & strLineEndChar) as text
047  else if itemNo = numCntList then
048    #最後の行
049    set strOutputText to (strOutputText & strLineText) as text
050  else
051    #それ以外の行
052    set strOutputText to (strOutputText & strLineText & strLineEndChar) as text
053  end if
054end repeat
055
056#テキストを戻す
057tell application "Script Editor"
058  tell front document
059    tell selection
060      set contents to strOutputText as text
061    end tell
062  end tell
063end tell
AppleScriptで生成しました

|

スクリプトエディターの入力支援(Path to)


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005#com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "AppKit"
010use scripting additions
011property refMe : a reference to current application
012
013
014set listChooser to {"me", "system folder", "system preferences", "startup disk", "#", "users folder", "shared documents", "home folder", "#", "trash", "temporary items", "#", "desktop", "documents folder", "downloads folder", "movies folder", "music folder", "pictures folder", "public folder", "sites folder", "#", "applications folder", "utilities folder", "#", "library folder", "application support", "keychain folder", "fonts", "favorites folder", "Folder Action scripts", "help", "preferences", "scripting additions folder", "scripts folder", "services folder", "startup items", "workflows folder"} as list
015
016###ダイアログを前面に出す
017set strName to (name of current application) as text
018if strName is "osascript" then
019  tell application "Finder" to activate
020else
021  tell current application to activate
022end if
023###
024set strTitle to ("選んでください") as text
025set strPrompt to ("選んだ項目で戻します") as text
026try
027  set objResponse to (choose from list listChooser with title strTitle with prompt strPrompt default items (item 1 of listChooser) OK button name "OK" cancel button name "キャンセル" with empty selection allowed without multiple selections allowed)
028on error
029  log "エラーしました"
030  return "エラーしました"
031end try
032log class of objResponse
033if (class of objResponse) is boolean then
034  return "キャンセルしましたA"
035else if (class of objResponse) is list then
036  if objResponse is {} then
037    return "キャンセルしましたB"
038  else
039    set strResponse to (item 1 of objResponse) as text
040  end if
041end if
042if strResponse is "#" then
043  tell application "Finder"
044    set aliasPathToMe to (path to me) as alias
045  end tell
046  run script aliasPathToMe with parameters "再実行"
047  
048else if strResponse is "" then
049  tell application "Finder"
050    set aliasPathToMe to (path to me) as alias
051  end tell
052  run script aliasPathToMe with parameters "再実行"
053  
054end if
055#
056set ocidResponse to refMe's NSString's stringWithString:(strResponse)
057set ocidResponse to ocidResponse's stringByReplacingOccurrencesOfString:("folder") withString:("")
058set ocidResponse to ocidResponse's stringByReplacingOccurrencesOfString:("items") withString:("")
059set ocidResponse to ocidResponse's capitalizedString()
060set ocidResponse to ocidResponse's stringByReplacingOccurrencesOfString:(" ") withString:("")
061set strDirName to ocidResponse as text
062#
063if strDirName is "Me" then
064  set strScriptText to ("set aliasPathToMe to (path to " & strResponse & ") as alias") as text
065  set strScriptText to (strScriptText & "\n") as text
066  set strScriptText to (strScriptText & "set strPathToMe to (posix path of  aliasPathToMe)as text") as text
067  set strScriptText to (strScriptText & "\n") as text
068  set strScriptText to (strScriptText & "set ocidPathToMeStr to refMe's NSString's stringWithString:(strPathToMe)") as text
069  set strScriptText to (strScriptText & "\n") as text
070  set strScriptText to (strScriptText & "set ocidPathToMe  to ocidPathToMeStr's  stringByStandardizingPath()") as text
071  set strScriptText to (strScriptText & "\n") as text
072  set strScriptText to (strScriptText & "set ocidPathToMeURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidPathToMe ) isDirectory:(true)") as text
073  set strScriptText to (strScriptText & "\n") as text
074  set strScriptText to (strScriptText & "set ocidContainerDirPathURL to ocidPathToMeURL's URLByDeletingLastPathComponent()") as text
075  set strScriptText to (strScriptText & "\n") as text
076else
077  set strScriptText to ("set alias" & strDirName & "DirPath to (path to " & strResponse & " from user domain) as alias") as text
078  set strScriptText to (strScriptText & "\n") as text
079  set strScriptText to (strScriptText & "set str" & strDirName & "DirPath to (posix path of alias" & strDirName & "DirPath)as text") as text
080  set strScriptText to (strScriptText & "\n") as text
081  set strScriptText to (strScriptText & "set ocid" & strDirName & "DirPathStr to refMe's NSString's stringWithString:(str" & strDirName & "DirPath)") as text
082  set strScriptText to (strScriptText & "\n") as text
083  set strScriptText to (strScriptText & "set ocid" & strDirName & "DirPath  to ocid" & strDirName & "DirPathStr's  stringByStandardizingPath()") as text
084  set strScriptText to (strScriptText & "\n") as text
085  set strScriptText to (strScriptText & "set ocid" & strDirName & "DirPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocid" & strDirName & "DirPath ) isDirectory:(true)") as text
086  set strScriptText to (strScriptText & "\n") as text
087end if
088
089
090##############################
091#####ダイアログ
092##############################
093tell current application
094  set strName to name as text
095end tell
096if strName is "osascript" then
097  tell application "Finder"
098    activate
099  end tell
100else
101  tell current application
102    activate
103  end tell
104end if
105set strMes to "AppleScriptです"
106set aliasIconPath to (POSIX file "/System/Applications/Utilities/Script Editor.app/Contents/Resources/AppIcon.icns") as alias
107try
108  set recordResult to (display dialog strMes with title "戻り値です" default answer strScriptText buttons {"クリップボードにコピー", "終了", "再実行"} default button "再実行" cancel button "終了" giving up after 20 with icon aliasIconPath without hidden answer) as record
109on error
110  return "エラーしました"
111end try
112if (gave up of recordResult) is true then
113  return "時間切れです"
114end if
115##############################
116#####自分自身を再実行
117##############################
118if button returned of recordResult is "再実行" then
119  tell application "Finder"
120    set aliasPathToMe to (path to me) as alias
121  end tell
122  run script aliasPathToMe with parameters "再実行"
123end if
124##############################
125#####値のコピー
126##############################
127if button returned of recordResult is "クリップボードにコピー" then
128  try
129    set strText to text returned of recordResult as text
130    ####ペーストボード宣言
131    set appPasteboard to refMe's NSPasteboard's generalPasteboard()
132    set ocidText to (refMe's NSString's stringWithString:(strText))
133    appPasteboard's clearContents()
134    appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
135  on error
136    tell application "Finder"
137      set the clipboard to strText as text
138    end tell
139  end try
140end if
141
142
143return 0
AppleScriptで生成しました

|

新しいアプリケーション・スクリプトを作成する


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "Appkit"
use framework "UniformTypeIdentifiers"
use scripting additions
property refMe : a reference to current application


##############################
#####スクリプトメニューから実行させない
##############################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    set aliasPathToMe to path to me as alias
    tell application "Script Editor"
      open aliasPathToMe
    end tell
return "中止しました"
  end tell
else
  tell current application
    activate
  end tell
end if

set strBundleID to ("com.apple.FontBook") as text
set strAppFileName to (strBundleID & ".app") as text

set strFilePath to ("~/Desktop/" & strAppFileName) as text


set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
set aliasFilePath to (ocidFilePathURL's absoluteURL()) as «class furl»


set strScript to ("#!/usr/bin/env osascript\n----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\n#\n(*\nログイン項目登録用\n起動時に起動後『隠す』処理\nファイル>書き出す…からアプリケーションに書き出し\nログイン項目に登録する\n設定項目のバンドルIDは\nhttps://github.com/force4u/AppleScript/blob/main/Script%20Menu/Developer/Get/getAppBundleID.applescript\nを使って取得できます\n*)\n#com.cocolog-nifty.quicktimer.icefloe\n----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\nuse AppleScript version \"2.8\"\nuse framework \"Foundation\"\nuse scripting additions\n###設定項目\nset strBundleID to (\"" & strBundleID & "\") as text\n###起動\ntell application id strBundleID\nlaunch\nend tell\ndelay 3\n###起動待ち 最大60回\nrepeat 60 times\ntell application id strBundleID\nactivate\nset boolFrontMost to frontmost as boolean\nend tell\nif boolFrontMost is true then\nexit repeat\nelse\ndelay 0.25\nend if\nend repeat\n###名前の取得\ntell application id strBundleID\nset strAppName to name as text\nend tell\n###隠す処理\ntell application \"System Events\"\ntell application process strAppName\nset visible to false\nend tell\nend tell") as text


tell application "Script Editor"
  
  make new document with properties {contents:strScript}
  tell front document
    activate
compile
  end tell
  save front document as "application" in aliasFilePath without run only, startup screen and stay open
  close front document saving no
end tell

|

新規スクリプトを作成する


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
##
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

##ファイル名
set strFileName to doGetDateNo("yyyyMMddhhmmss")
set strFileName to (strFileName & ".applescript") as text
set strDateNO to doGetDateNo("yyyyMMdd")

set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirURL to ocidURLsArray's firstObject()
set ocidSaveFilePathURL to ocidDesktopDirURL's URLByAppendingPathComponent:(strFileName)

#################################
###ダイアログ用に値を用意
#################################
set strScript to "#!/usr/bin/env osascript\r----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\r#com.cocolog-nifty.quicktimer.icefloe\r#" & strDateNO & "作成\r----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\ruse AppleScript version \"2.8\"\ruse framework \"Foundation\"\ruse framework \"AppKit\"\ruse scripting additions\r\rproperty refMe : a reference to current application\r\r\r"
#################################
###【3】ダイアログを前面に
#################################
tell current application
  set strName to name as text
end tell
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
###ダイアログ
set strIconPath to ("/System/Applications/Utilities/Script Editor.app/Contents/Resources/AppIcon.icns") as text
set aliasIconPath to (POSIX file strIconPath) as alias
set recordResult to (display dialog "スクリプト戻り値です" with title "スクリプト" default answer strScript buttons {"クリップボードにコピー", "キャンセル", "スクリプトエディタで開く"} default button "スクリプトエディタで開く" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer)
###クリップボードにコピー
if button returned of recordResult is "クリップボードにコピー" then
  set strText to text returned of recordResult as text
  ####ペーストボード宣言
  set appPasteboard to refMe's NSPasteboard's generalPasteboard()
  set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
end if


###OK押したらスクリプト生成
if button returned of recordResult is "スクリプトエディタで開く" then
  ###スクリプトをテキストで保存
  set ocidScript to refMe's NSString's stringWithString:(strScript)
  set listDone to ocidScript's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF16LittleEndianStringEncoding) |error|:(reference)
  delay 0.5
  set aliasSaveFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
  ###保存したスクリプトを開く
  tell application "Script Editor"
    open aliasSaveFilePath
  end tell
end if


to doGetDateNo(strDateFormat)
  ####日付情報の取得
  set ocidDate to current application's NSDate's |date|()
  ###日付のフォーマットを定義
  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
ocidNSDateFormatter's setDateFormat:strDateFormat
  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo

|

Script Editor Scripts テンプレート

選択範囲の『後』挿入

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

property strBundleID : "com.apple.ScriptEditor2" as text


set strInsertScript to "tell application \"System Events\"\r\ttell process \"SOME APP\"\r\tend tell\rend tell" as text

tell application id strBundleID
  tell the front document
    set strSelectedContents to the contents of selection
  end tell
end tell

set strSelectedContents to strSelectedContents & "\r" & strInsertScript & "\r" & "" as text

tell application id strBundleID
  tell the front document
    set contents of selection to strSelectedContents
    set selection to {}
  end tell
end tell

|

[applescript://]スキームapplescriptのデフォルトのエディタを変更する


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
com.cocolog-nifty.quicktimer.icefloe
applescript://
*)
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application


###設定項目ドキュメントのURL
set strScheme to "applescript://" as text
###NSURL
set ocidScheme to refMe's NSURL's URLWithString:(strScheme)
###ワークスペース初期化
set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
###URLタイプのデフォルトアプリケーション
set ocidAppPathURL to appShardWorkspace's URLsForApplicationsToOpenURL:(ocidScheme)

###ダイアログ用のアプリケーション名リスト
set listAppName to {} as list
###アプリケーションのURLを参照させるためのレコード
set ocidBrowserDictionary to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
####################################################
####httpがスキームとして利用可能なアプリケーション一覧を取得する
####################################################
repeat with itemAppPathURL in ocidAppPathURL
  ###アプリケーションの名前
  set listResponse to (itemAppPathURL's getResourceValue:(reference) forKey:(refMe's NSURLNameKey) |error|:(missing value))
  set strAppName to (item 2 of listResponse) as text
  log "ブラウザの名前は:" & strAppName & "です"
  copy strAppName to end of listAppName
  ####パス
  set aliasAppPath to itemAppPathURL's absoluteURL() as alias
  log "ブラウザのパスは:" & aliasAppPath & "です"
  ####バンドルID取得
  set ocidAppBunndle to (refMe's NSBundle's bundleWithURL:(itemAppPathURL))
  set ocidBunndleID to ocidAppBunndle's bundleIdentifier
  set strBundleID to ocidBunndleID as text
  log "ブラウザのBunndleIDは:" & strBundleID & "です"
(ocidBrowserDictionary's setObject:(itemAppPathURL) forKey:(strAppName))
end repeat

################################
##ダイアログ
################################
###ダイアログを前面に
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    activate
  end tell
else
  tell current application
    activate
  end tell
end if
try
  set listResponse to (choose from list listAppName with title "選んでください" with prompt "URLを開くアプリケーションを選んでください" default items (item 1 of listAppName) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed)
on error
  log "エラーしました"
return "エラーしました"
end try
if listResponse is false then
return "キャンセルしました"
end if
set strResponse to (item 1 of listResponse) as text
################################
##アプリケーションのURLを取得する
################################
###アプリケーションのURLを取り出す
set ocidAppPathURL to ocidBrowserDictionary's objectForKey:(strResponse)
log className of ocidAppPathURL as text
log ocidAppPathURL as alias

################################
##デフォルトに設定する
################################

appShardWorkspace's setDefaultApplicationAtURL:(ocidAppPathURL) toOpenURLsWithScheme:("applescript") completionHandler:(missing value)





|

"applescript://com.apple.scripteditor" オプション

ファイル名指定


【スクリプトエディタで開く】



action=new
name=ファイル名
script=%エンコードされたスクリプト

|

スクリプトメニューやコマンドラインから実行させない

【スクリプトエディタで開く】

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions


##############################
#####スクリプトメニューから実行させない
##############################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    set aliasPathToMe to path to me as alias
    tell application "Script Editor"
      open aliasPathToMe
    end tell
    return "中止しました"
  end tell
else
  tell current application
    activate
  end tell
end if



【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
com.cocolog-nifty.quicktimer.icefloe
*)
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

##############################
#####ダイアログを前面に
##############################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
doDisplayAlert()
else
  tell current application to activate
doDisplayAlert()
end if



on doDisplayAlert()
  
  display alert ""
  
end doDisplayAlert

|

[SCPT]拡張子scptのスクリプトを拡張子applescriptのテキストに変換する

【スクリプトエディタで開く】


tell application "Finder"
  set listAliasPath to selection as list
end tell


doScriptRun(listAliasPath)

on doScriptRun(argFileInput)
  set numCntSelectedObject to (count of argFileInput) as integer
  if numCntSelectedObject = 0 then
    return "未選択です"
  end if
  repeat with itemFilePath in argFileInput
    set aliasFilePath to itemFilePath as alias
    set objInfo to get info for aliasFilePath
    if (folder of objInfo) is true then
      log "フォルダなので処理しない"
    else if (type identifier of objInfo) is "com.apple.applescript.text" then
      log "すでにテキスト形式なので処理しない"
    else if (type identifier of objInfo) is "com.apple.applescript.script" then
      set strExtension to name extension of objInfo
      set strNewExtension to "applescript"
      set strName to (name of objInfo) as text
      tell application "Finder"
        set aliasSaveDirPath to (container of aliasFilePath) as alias
        set strSaveDirPath to POSIX path of aliasSaveDirPath as text
      end tell
      set strFilePath to POSIX path of aliasFilePath as text
      set strSaveFilePath to doReplace(strFilePath, ".scpt", ".applescript") as text
      set aliasSavePath to POSIX file strSaveFilePath as «class furl»
      
      tell application "Script Editor"
        open aliasFilePath
        save the front document as "text" in aliasSavePath
        close front document
      end tell
      set theComandText to ("chmod 755  \"" & strSaveFilePath & "\"") as text
      do shell script theComandText
      tell application "Finder"
        move aliasFilePath to trash
      end tell
    else
      log "スクリプト形式以外は処理しない"
    end if
  end repeat
end doScriptRun


to doReplace(theText, orgStr, newStr)
  set oldDelim to AppleScript's text item delimiters
  set AppleScript's text item delimiters to orgStr
  set tmpList to every text item of theText
  set AppleScript's text item delimiters to newStr
  set tmpStr to tmpList as text
  set AppleScript's text item delimiters to oldDelim
  return tmpStr
end doReplace

|

[Open]スクリプトを開くスクリプト

ダウンロード - openscript.zip

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
#                       com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7

use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

set objFileManager to refMe's NSFileManager's defaultManager()

###########################
#####このファイルへのパス
set aliasPathToMe to path to me as alias
#####
set strPathToMe to POSIX path of aliasPathToMe as text
set ocidPathToMeStr to refMe's NSString's stringWithString:strPathToMe
set ocidPathToMePath to ocidPathToMeStr's stringByStandardizingPath()
set ocidPathToMePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidPathToMePath isDirectory:false

set ocidContainerDirURL to ocidPathToMePathURL's URLByDeletingLastPathComponent()
set ocidContentsDirPathURL to ocidContainerDirURL's URLByAppendingPathComponent:"Scripts" isDirectory:true
###########################
set ocidPropertiesForKeys to {refMe's NSURLPathKey, refMe's NSURLNameKey}
set ocidOption to refMe's NSDirectoryEnumerationSkipsHiddenFiles
set listResult to objFileManager's contentsOfDirectoryAtURL:ocidContentsDirPathURL includingPropertiesForKeys:ocidPropertiesForKeys options:ocidOption |error|:(reference)
set ocidContentsArray to item 1 of listResult
log ocidContentsArray as list

###########################
##TURE値
set ocidTrue to (refMe's NSNumber's numberWithBool:true)
##格納用のARRAY
set ocidFileNameArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
###URLの数だけ繰り返し
repeat with itemContentsArray in ocidContentsArray
    ###レギュラーファイルキーを取得
    set listResult to (itemContentsArray's getResourceValue:(reference) forKey:(refMe's NSURLIsRegularFileKey) |error|:(reference))
    ###ファイル?
    set boolIsRegularFileKey to item 2 of listResult
    ###ファイルならリストに加える
    if boolIsRegularFileKey is ocidTrue then
        set ocidFileName to itemContentsArray's lastPathComponent()
        (ocidFileNameArray's addObject:ocidFileName)
    end if
end repeat
####並び替え
set ocidSortArray to ocidFileNameArray's sortedArrayUsingSelector:"localizedCaseInsensitiveCompare:"
set listSortArray to ocidSortArray as list

###########################
#####ファイル名のリストでダイアログ
try
    set objResponse to (choose from list listSortArray with title "選んでください" with prompt "開くスクリプトを選んでください" default items (item 1 of listSortArray) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed)
on error
    log "エラーしました"
    return
end try
if objResponse is false then
    log "キャンセルしました"
    return
end if
######選んだ戻り値
set strFileName to (objResponse) as text

###########################
#####開くファイルのURL
set ocidOpenFilePathURL to ocidContentsDirPathURL's URLByAppendingPathComponent:strFileName isDirectory:false
log className() of ocidOpenFilePathURL as text
log ocidOpenFilePathURL's |Path|
set aliasFilePathURL to ocidOpenFilePathURL as alias
####開く
tell application "Script Editor"
    launch
    activate
    open aliasFilePathURL
end tell

|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code Wacom webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom