指定フォルダから、指定拡張子のファイルを取得し、取得したファイルがエイリアス書類だったらオリジナルのパスを返すAppleScriptです。
AppleScriptを指定スケジュールで実行するAppleScriptを作成しており、スケジュールフォルダ以下に「毎月15日 15時」といった名前のフォルダを作っておき、その中に入れたAppleScriptを指定スケジュールで実行するようにしてありました。
ただ、フォルダ内に入れるのが「AppleScript書類そのもの」だと、運用上いろいろまずい(同じScriptの複製が大量にできてしまうとか)ので、エイリアスを入れても反応するように、本Scriptを書いてみた次第です。
割とちゃんと動いているように見えます。
AppleScript名:指定フォルダ内から指定拡張子のファイルを取得し、エイリアスだったらオリジナルのパスをPOSIX pathで取得.scptd |
— – Created by: Takaaki Naganoya – Created on: 2025/09/19 — – Copyright © 2025 Piyomaru Software, All Rights Reserved — use AppleScript version "2.8" use framework "Foundation" use scripting additions set aRoot to choose folder set scptList to getFilePathListWithResolveAlias(aRoot, "scpt") of me –> {"/Users/me/Documents/sample2.scpt", "/Users/me/Documents/sample1.scpt"} on getFilePathListWithResolveAlias(aFol, aExt) set aURL to current application’s |NSURL|’s fileURLWithPath:(POSIX path of aFol) # 指定フォルダの直下のファイルを取得 set filePaths to current application’s NSFileManager’s defaultManager’s ¬ contentsOfDirectoryAtURL:aURL ¬ includingPropertiesForKeys:{current application’s NSURLNameKey} ¬ options:(current application’s NSDirectoryEnumerationSkipsHiddenFiles) ¬ |error|:(missing value) set f0List to filePaths as list if f0List = {} then return {} set f2List to {} repeat with i in f0List set tmpPath1 to POSIX path of i set tmpPath2 to (my fullpathOfOriginalFileForAlias:tmpPath1) set tmpPath to (current application’s NSString’s stringWithString:(tmpPath2)) set the end of f2List to tmpPath as string end repeat return f2List end getFilePathListWithResolveAlias –エイリアスファイルのパスからオリジナルのファイルパス(POSIX Path)を返す on fullpathOfOriginalFileForAlias:posixPath tell current application’s |NSURL| set anNSURL to its fileURLWithPath:posixPath set theData to its bookmarkDataWithContentsOfURL:anNSURL |error|:(missing value) set theResult to its resourceValuesForKeys:{current application’s NSURLPathKey} fromBookmarkData:theData end tell return (theResult’s objectForKey:(current application’s NSURLPathKey)) as text end fullpathOfOriginalFileForAlias: |
(Visited 1 times, 1 visits today)