AppleScript名:相対パスから絶対パスを計算してを求める v2 |
— Created 2017-11-11 by Takaaki Naganoya use AppleScript version "2.4" use scripting additions use framework "Foundation" set absolutePath to "/Users/me/Documents/–Book 1「AppleScript最新リファレンス」/5000 iOSデバイスとの連携/5100 iOSデバイスからMacに画面を出力するAirServer.md" set relativePath to "../9999_images/img-1.jpg" set relativePath to calcAbsolutePath(absolutePath, relativePath) of me –> "/Users/me/Documents/–Book 1「AppleScript最新リファレンス」/9999_images/img-1.jpg" on calcAbsolutePath(aAbsolutePOSIXfile, bRelativePOSIXfile) set aStr to current application’s NSString’s stringWithString:aAbsolutePOSIXfile set bStr to current application’s NSString’s stringWithString:bRelativePOSIXfile set aList to aStr’s pathComponents() as list set bList to bStr’s pathComponents() as list set aLen to length of aList set aCount to 1 repeat with i in bList set j to contents of i if j is not equal to ".." then exit repeat end if set aCount to aCount + 1 end repeat set tmp1List to items 1 thru (aLen – aCount) of aList set tmp2List to items aCount thru -1 of bList set allRes to current application’s NSString’s pathWithComponents:(tmp1List & tmp2List) return allRes as text end calcAbsolutePath |
More from my site
(Visited 30 times, 1 visits today)