AppleScript名:2つのパスの相対パスを求める v3 |
— Created 2017-01-28 by Takaaki Naganoya — Modified 2017-01-30 by Shane Stanley — Modified 2017-02-03 by Takaaki Naganoya use AppleScript version "2.4" use scripting additions use framework "Foundation" –Markdown書類(フルパス) set aFile to "/Users/me/Documents/ぴよまるソフトウェア/書籍原稿/–Book 1a「AppleScript最新リファレンス バージョン2.7対応」/5000 iOSデバイスとの連携/5100 iOSデバイスからMacに画面を出力するAirServer.md" –リンク画像(フルパス) set bFile to "/Users/me/Documents/ぴよまるソフトウェア/書籍原稿/–Book 1a「AppleScript最新リファレンス バージョン2.7対応」/9999_images/img-1.php.jpeg" set relativePath to calcRelativePath(aFile, bFile) of me –> "../9999_images/img-1.php.jpeg" on calcRelativePath(aPOSIXfile, bPOSIXfile) set aStr to current application’s NSString’s stringWithString:aPOSIXfile set bStr to current application’s NSString’s stringWithString:bPOSIXfile set aList to aStr’s pathComponents() as list set bList to bStr’s pathComponents() as list set aLen to length of aList set bLen to length of bList if aLen ≥ bLen then copy aLen to aMax else copy bLen to aMax end if repeat with i from 1 to aMax set aTmp to contents of item i of aList set bTmp to contents of item i of bList if aTmp is not equal to bTmp then exit repeat end if end repeat set bbList to items i thru -1 of bList set aaItem to (length of aList) – i set tmpStr to {} repeat with ii from 1 to aaItem set the end of tmpStr to ".." end repeat set allRes to current application’s NSString’s pathWithComponents:(tmpStr & bbList) return allRes as text end calcRelativePath |
(Visited 82 times, 1 visits today)