指定フォルダから、指定拡張子のファイルを取得し、取得したファイルがエイリアス書類だったらオリジナルのパスを返すAppleScriptです。
AppleScriptを指定スケジュールで実行するAppleScriptを作成しており、スケジュールフォルダ以下に「毎月15日 15時」といった名前のフォルダを作っておき、その中に入れたAppleScriptを指定スケジュールで実行するようにしてありました。

ただ、フォルダ内に入れるのが「AppleScript書類そのもの」だと、運用上いろいろまずい(同じScriptの複製が大量にできてしまうとか)ので、エイリアスを入れても反応するように、本Scriptを書いてみた次第です。
割とちゃんと動いているように見えます。
2025/9/29修正:
処理対象にエイリアス書類「ではなく」本物のファイルが指定されていた(=エイリアス書類ではなかった)場合にエラーになっていました。作成・使用目的は「エイリアス書類の実体の追跡」ではあったものの、実体のファイルに行き当たった場合にエラーになるのは意図しない動作です。
このため、掲載リストを一部修正しました。
| AppleScript名:指定フォルダ内から指定拡張子のファイルを取得し、エイリアスだったらオリジナルのパスをPOSIX pathで取得.scptd |
| — – Created by: Takaaki Naganoya – Created on: 2025/09/19 – Modified on: 2025/09/29 — – 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 if theResult = missing value then return posixPath return (theResult’s objectForKey:(current application’s NSURLPathKey)) as text end fullpathOfOriginalFileForAlias: |
(Visited 8 times, 1 visits today)




