AppleScript Basic Path

フォルダ判定


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

#!/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

set strPathCommand to ("/bin/echo \"$HOME/Desktop/\"") as text
set strFilePath to (do shell script strPathCommand) as text

set aliasFilePath to (POSIX file strFilePath) as alias
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))
set aliasFilePath to (ocidFilePathURL's absoluteURL()) as alias

tell application "Finder"
  set strKind to (kind of aliasFilePath) as text
end tell
if strKind is "フォルダ" then
log "フォルダ"
else
log "フォルダ以外"
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 framework "AppKIt"
use framework "UniformTypeIdentifiers"
use scripting additions

property refMe : a reference to current application

set strFilePath to ("~/Desktop/") 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))
set listBoole to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error|:(reference))
set boolIsDir to (item 2 of listBoole) as boolean
if boolIsDir is true then
log "フォルダ"
else
log "フォルダ以外"
end if


#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
#################################################
STR_FILE_PATH="$HOME/Desktop"
if [ -d "$STR_FILE_PATH" ]; then
echo "$STR_FILE_PATH はディレクトリです"
elif [ -f "$STR_FILE_PATH" ]; then
echo "$STR_FILE_PATH はファイルです"
else
echo "$STR_FILE_PATH は存在しません"
fi

exit 0


|

1:Posix file

Alias

tell application "Finder"

  set aliasLibraryDirPath to (path to library folder from local domain) as alias

  --> alias "Macintosh HD:Library:"

  log class of aliasLibraryDirPath 

  -->alias

  log kind of aliasLibraryDirPath as text 

  --> (*フォルダ*)

end tell



set strPath to "Macintosh HD:Library:"

log strPath 

-->(*Macintosh HD:Library:*)

log class of strPath

-->(*text*)



set aliasPath to strPath as alias

log aliasPath

-->(*alias Macintosh HD:Library:*)

log class of aliasPath

-->(*alias*)


tell application "Finder"

  set aliasLibraryDirPath to (path to library folder from user domain) as alias

  --> alias "Macintosh HD:Users:ユーザー名:Library:"

  log class of aliasLibraryDirPath

  -->alias

  log kind of aliasLibraryDirPath as text

  --> (*フォルダ*)

end tell



set strLibraryDirPath to aliasLibraryDirPath as text

log strLibraryDirPath

-->(*Macintosh HD:Users:ユーザー名:Library:*)

log class of strLibraryDirPath

(*text*)


set strPath to strLibraryDirPath & "CloudStorage:OneDrive-個人用:Microsoft Edge Collections:"

log strPath

-->(*Macintosh HD:Users:ユーザー名:Library:OneDrive-個人用:Microsoft Edge Collections:*)

log class of strPath

-->(*text*)



set aliasPath to strPath as alias

log aliasPath

-->(*alias Macintosh HD:Users:ユーザー名:Library:CloudStorage:OneDrive-個人用:Microsoft Edge Collections:*)

log class of aliasPath

-->(*alias*)


furl
as «class furl»

aliasが『実体』があるのに対して
furlは『実体が無い』パス
(例:これから生成するファイルの保存先等 今はまだ実物が無いパス』

【留意】furlがあるとターミナルから実行出来なくなる場合がある
as «class furl»

furlがあると、テキストとしての保存時に文字コードがUTF16になる
そのため、ターミナルから実行出来なくなる『場合』がある

set furlFilePath to choose file name

log class of furlFilePath

-->(*«class furl»*)



tell application "Finder"

  set aliasDesktopDirPath to (path to desktop folder from user domain) as alias

  --> alias "Macintosh HD:Users:ユーザー名:Desktop:"

  log class of aliasDesktopDirPath

  -->alias

  log kind of aliasDesktopDirPath as text

  --> (*フォルダ*)

end tell




tell application "Finder"

  set aliasFolderDirPath to furlFilePath as «class furl»

  log aliasFolderDirPath

  --> (*file Macintosh HD:Users:ユーザー名:Desktop:名称未設定*)

  log class of aliasFolderDirPath

  --> (*«class furl»*)

end tell


set strFolderDirPath to aliasFolderDirPath as text

set aliasFolderDirPath to strFolderDirPath as «class furl»



set strFilePath to "Macintosh HD:Users:ユーザー名:Desktop:名称未設定.txt" as text

set furlFilePath to strFilePath as «class furl»





Folder

tell application "Finder"

  set folderLibraryDirPath to folder (path to library folder from local domain)

  --> folder "Library" of startup disk

  log class of folderLibraryDirPath

  --> folder

  log kind of folderLibraryDirPath as text

  --> (*フォルダ*)

end tell


tell application "Finder"

  set folderDocumentationPath to (folder "Documentation" of folderLibraryDirPath)

  --> folder "Documentation" of folder "Library" of startup disk

  log class of folderDocumentationPath

  --> folder

  log kind of folderDocumentationPath as text

  --> (*フォルダ*)

end tell




file

tell application "Finder"

  set folderLibraryDirPath to folder (path to library folder from local domain)

  --> folder "Library" of startup disk

  log class of folderLibraryDirPath

  --> folder

  log kind of folderLibraryDirPath as text

  --> (*フォルダ*)

end tell


tell application "Finder"

  set aliasDocumentationPath to (folder "Documentation" of folderLibraryDirPath) as alias

  --> alias "Macintosh HD:Library:Documentation:"

  log class of aliasDocumentationPath

  --> alias

  log kind of aliasDocumentationPath as text

  --> (*フォルダ*)

end tell



tell application "Finder"

  set fileFilePath to (file "Warranty.rtf" of aliasDocumentationPath)

  log class of fileFilePath

  --> document file

  log kind of fileFilePath as text

  -->(*リッチテキスト書類*)

end tell



|

ファイル名置換 WINDOWS互換


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
----+----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 strFileName to "*><?/" as text

set strNewFileName to doFileName4Win(strFileName)
log strNewFileName

#######################################
###ファイル名に使えない文字を全角に置換(Win互換)
#######################################
to doFileName4Win(atgFileName)
  ###受け取った値をテキストに
  set strFileName to atgFileName as text
  set ocidRetuenFileName to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidRetuenFileName's setString:(strFileName)
  ###置換レコード
  set ocidLength to ocidRetuenFileName's |length|()
  set ocidRange to refMe's NSMakeRange(0, ocidLength)
  set ocidOption to (refMe's NSCaseInsensitiveSearch)
  ###基本レコード
  set recordProhibit to {|\\|:"¥", |<|:"<", |>|:">", |*|:"*", |?|:"?", |"|:""", |\||:"|", |/|:"/", |:|:":"} as record
  set ocidProhibitDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidProhibitDict's setDictionary:(recordProhibit)
  ###キーのリストを取出して
  set ocidKeyArray to ocidProhibitDict's allKeys()
  ###キーの数だけ繰り返し
  repeat with itemKey in ocidKeyArray
    ##キーから
    set strKey to itemKey as text
    ##値を取出して
    set strValue to (ocidProhibitDict's valueForKey:(itemKey)) as text
    ##キー文字をヴァリュー文字に置換
(ocidRetuenFileName's replaceOccurrencesOfString:(strKey) withString:(strValue) options:(ocidOption) range:(ocidRange))
  end repeat
  ##置換されたテキストを
  set strRetuenFileName to ocidRetuenFileName as text
  ###戻す
return strRetuenFileName
end doFileName4Win

|

[起動時に削除する項目]Cleanup At Startup と TemporaryItems

誤解している方が多いが
Caches内は=キャッシュなので 自動削除しないディレクトリとなります。
なので
/Users/ユーザー名/Library/Caches/Cleanup At Startup
/Users/ユーザー名/Library/Caches/TemporaryItems
内は
起動時に削除はされません

使い勝手がいいのは以下の2ポイントかな?と思います。
セキュリティ上他者が見ても大丈夫な物なら
/tmp
セキュリティ上自分だけのアクセス権で…なら
/var/folders
/var/foldersを利用する場合は
自分だけアクセス権の『C』『T』を利用する
(c=キャッシュ的な意味合い? T=テンポラリーのT)
Screencapture1720x342



#!/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()


##########################
###起動時に削除するフォルダ
##########################
#######/private/tmp = /tmp 内は起動時全部削除になります
-->中間ファイルは全て不要なので次回再起動時に自動削除になります
set strCleanupAtStartupPath to "/private/tmp/Cleanup At Startup/" as text
set ocidCleanupAtStartup to refMe's NSString's stringWithString:strCleanupAtStartupPath
set ocidCleanupAtStartup to ocidCleanupAtStartup's stringByStandardizingPath()
set ocidCleanupAtStartupURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidCleanupAtStartup isDirectory:true
set strCleanupAtStartupPath to ocidCleanupAtStartupURL's |path|() as text

####アクセス権777で作成
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions)
objFileManager's createDirectoryAtURL:ocidCleanupAtStartupURL withIntermediateDirectories:true attributes:ocidAttrDict |error|:(reference)

#######/private/tmp = /tmp 内は起動時全部削除になります
-->中間ファイルは全て不要なので次回再起動時に自動削除になります
set strCleanupAtStartupPath to "/private/tmp/TemporaryItems/" as text
set ocidCleanupAtStartup to refMe's NSString's stringWithString:strCleanupAtStartupPath
set ocidCleanupAtStartup to ocidCleanupAtStartup's stringByStandardizingPath()
set ocidCleanupAtStartupURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidCleanupAtStartup isDirectory:true
set strCleanupAtStartupPath to ocidCleanupAtStartupURL's |path|() as text

####アクセス権777で作成
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions)
objFileManager's createDirectoryAtURL:ocidCleanupAtStartupURL withIntermediateDirectories:true attributes:ocidAttrDict |error|:(reference)



#!/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()



##########################
###起動時に削除するフォルダ
##########################
#####Cleanup At Startup
(*/var/folders/XX/XXXXXXXXXXXXXXXXXXXXX/Cleanup At Startup*)
set ocidFilePathURL to objFileManager's temporaryDirectory()
set ocidFilePathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
set codiCleanupAtStartupURL to ocidFilePathURL's URLByAppendingPathComponent:"Cleanup At Startup" isDirectory:true
set strCleanupAtStartupPath to codiCleanupAtStartupURL's |path|() as text
####アクセス権777で作成
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions)
objFileManager's createDirectoryAtURL:codiCleanupAtStartupURL withIntermediateDirectories:true attributes:ocidAttrDict |error|:(reference)


#####TemporaryItems
(*/var/folders/XX/XXXXXXXXXXXXXXXXXXXXX/TemporaryItems*)
set ocidFilePathURL to objFileManager's temporaryDirectory()
set ocidFilePathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
set codiCleanupAtStartupURL to ocidFilePathURL's URLByAppendingPathComponent:"TemporaryItems" isDirectory:true
set strCleanupAtStartupPath to codiCleanupAtStartupURL's |path|() as text
####アクセス権777で作成
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions)
objFileManager's createDirectoryAtURL:codiCleanupAtStartupURL withIntermediateDirectories:true attributes:ocidAttrDict |error|:(reference)



#!/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()


##########################
###起動時に削除するフォルダ
##########################
#####テンポラリーフォルダ Cleanup At Startupは基本起動時フォルダごと削除される
(*/var/folders/XX/XXXXXXXXXXXXXXXXXXXXX/T/Cleanup At Startup*)
set ocidFilePathURL to objFileManager's temporaryDirectory()
set codiCleanupAtStartupURL to ocidFilePathURL's URLByAppendingPathComponent:"Cleanup At Startup" isDirectory:true
set strCleanupAtStartupPath to codiCleanupAtStartupURL's |path|() as text
####アクセス権777で作成
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions)
objFileManager's createDirectoryAtURL:codiCleanupAtStartupURL withIntermediateDirectories:true attributes:ocidAttrDict |error|:(reference)


#####テンポラリーフォルダ TemporaryItemsは基本自動生成される
(*/var/folders/XX/XXXXXXXXXXXXXXXXXXXXX/T/TemporaryItems*)
set ocidFilePathURL to objFileManager's temporaryDirectory()
set codiCleanupAtStartupURL to ocidFilePathURL's URLByAppendingPathComponent:"TemporaryItems" isDirectory:true
set strCleanupAtStartupPath to codiCleanupAtStartupURL's |path|() as text
####アクセス権777で作成
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions)
objFileManager's createDirectoryAtURL:codiCleanupAtStartupURL withIntermediateDirectories:true attributes:ocidAttrDict |error|:(reference)


|

[NSURLIsDirectoryKey]フォルダか?

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


property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSURL : a reference to refMe's NSURL

set strFilePath to "~/Desktop"
set ocidFilePath to refNSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePath's stringByStandardizingPath
set ocidFilePathURL to refNSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:true

####フォルダ?ファイル?を調べる
set listResult to ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error|:(reference)
set boolUrlIsDir to (item 2 of listResult) as boolean
####ファイルなら
if boolUrlIsDir is true then
log "ディレクトリです"
else if boolUrlIsDir is false then
log "ファイルです"
end if

|

[Basic]Path

001

1:Posix file
alias
https://quicktimer.cocolog-nifty.com/icefloe/2023/02/post-53f288.html

2:Posix path

3:Strings
https://quicktimer.cocolog-nifty.com/icefloe/2023/02/post-4e2867.html

4:URL
https://quicktimer.cocolog-nifty.com/icefloe/2023/02/post-738998.html

5:Javascript
https://quicktimer.cocolog-nifty.com/icefloe/2023/02/post-5ffea1.html

|

3:String-Path

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


property refMe : a reference to current application
property refNSString : a reference to refMe's NSString


#########
set strFilePath to "/Library/Documentation/Warranty.rtf" as text
-->text

set ocidFilePath to refNSString's stringWithString:strFilePath
(*__NSCFString*)

set ocidFilePath to ocidFilePath's stringByStandardizingPath
(*NSPathStore2*)

#################################
###最後のパス(主にファイル名)
set ocidFileName to ocidFilePath's lastPathComponent()
(*Warranty.rtf*)

###拡張子
set ocidExtensionName to ocidFileName's pathExtension()
(*rtf*)
(*__NSCFString*)

###最後のパス削除
set ocidContainerDirPath to ocidFilePath's stringByDeletingLastPathComponent()
(*/Library/Documentation*)

###拡張子削除
set ocidFilePath to ocidFilePath's stringByDeletingPathExtension()
(*/Library/Documentation/Warranty*)
(*NSPathStore2*)

###パス追加
set ocidFilePath to ocidContainerDirPath's stringByAppendingPathComponent:"Warranty"

###拡張子追加
set ocidFilePath to ocidFilePath's stringByAppendingPathExtension:"rtf"


####################################
set strFilePath to "~/" as text
-->text

set ocidFilePath to refNSString's stringWithString:strFilePath
(*__NSCFString*)

set ocidFilePath to ocidFilePath's stringByStandardizingPath
(*NSPathStore2*)

###パス追加
set ocidFilePath to ocidFilePath's stringsByAppendingPaths:{"Desktop", "Documents", "Downloads", "Pictures", "Movies"}
log ocidFilePath as list
log className() of ocidFilePath as text
-->(*__NSArrayM*)



#########################
###stringByExpandingTildeInPath

set strFilePath to "~/Library/Caches/" as text
-->text

set ocidFilePath to refNSString's stringWithString:strFilePath
-->(*__NSCFConstantString*)

set ocidFilePath to ocidFilePath's stringByExpandingTildeInPath()
(*/Users/ユーザー名/Library/Caches*)
-->(*NSPathStore2*)



#########################
###stringByStandardizingPath

set strFilePath to "~" as text
set ocidFilePath to refNSString's stringWithString:strFilePath

set ocidFilePath to ocidFilePath's stringByStandardizingPath()
(*/Users/ユーザー名*)
-->(*NSPathStore2*)


#########################
###stringByAbbreviatingWithTildeInPath

set ocidFilePath to ocidFilePath's stringByAbbreviatingWithTildeInPath()
(*~*)
-->(*NSPathStore2*)


#########################
###stringByResolvingSymlinksInPath
set strFilePath to "/private/tmp" as text
set ocidFilePath to refNSString's stringWithString:strFilePath
set ocidSymlinksInPath to ocidFilePath's stringByResolvingSymlinksInPath()
(*/tmp*)
(*NSPathStore2*)
log ocidSymlinksInPath as text
log className() of ocidSymlinksInPath as text


#########################
###
set strFilePath to "/System/Library/CoreServices/.SystemVersionPlatform.plist" as text
set ocidFilePath to refNSString's stringWithString:strFilePath
set ocidSymlinksInPath to ocidFilePath's stringByResolvingSymlinksInPath()
(*/System/Library/CoreServices/SystemVersion.plist*)
(*NSPathStore2*)
log ocidSymlinksInPath as text
log className() of ocidSymlinksInPath as text

|

4:URL

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

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

property refMe : a reference to current application


set strFilePath to "~/Desktop/NoName.txt" as text
(*~/Desktop/*)

set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
(*__NSCFString*)

set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
(*NSPathStore2*)

###############################
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
(*NSURL*)
log ocidFilePathURL's |path| as text
(*/Users/ユーザー名/Desktop/NoName.txt*)
log ocidFilePathURL's absoluteString() as text
(*file:///Users/ユーザー名/Desktop/NoName.txt*)
log ocidFilePathURL's absoluteURL() as text
(*Macintosh HD:Users:ユーザー名:Desktop: NoName.txt*)

###############################
####ファイル名
set ocidFileName to ocidFilePathURL's lastPathComponent()
(* NoName.txt*)

set ocidFileName to ocidFileName's stringByDeletingPathExtension()
(* NoName*)

####ベースファイル名-->ファイル名ー拡張子
set ocidBaseFileName to ocidFilePathURL's URLByDeletingPathExtension()
(*/Users/ユーザー名/Desktop/NoName*)

####拡張子
set ocidExtensionName to ocidFilePathURL's pathExtension()
(*txt*)

####コンテナディレクトリ
set ocidContainerDirURL to ocidFilePathURL's URLByDeletingLastPathComponent()
(*/Users/ユーザー名/Desktop*)

###############################

####コンテナディレクトリに新しいディレクトリ
set ocidNewDirPathURL to ocidContainerDirURL's URLByAppendingPathComponent:"NewFolder" isDirectory:true
(*/Users/ユーザー名/Desktop/NewFolder*)

####新しいディレクトリに新しいファイル
set ocidNewFilePathURL to ocidNewDirPathURL's URLByAppendingPathComponent:"NoName.txt" isDirectory:false
(*/Users/ユーザー名/Desktop/NewFolder/NoName.txt*)


|

5:Javascript

#!/usr/bin/env osascript -l JavaScript

//----+----1----+----2----+-----3----+----4----+----5----+----6----+----7

//

//

//

//

//                      com.cocolog-nifty.quicktimer.icefloe

//----+----1----+----2----+-----3----+----4----+----5----+----6----+----7

//Foundation この部分は定型

ObjC.import('Foundation')

//currentApplication

let objMe = Application.currentApplication();

//scripting additions

objMe.includeStandardAdditions = true;

//NSFileManager

let objFileManager = $.NSFileManager.defaultManager;


//NSURL定義するなら

let refNSURL = $.NSURL;


//Finder

let appFinder = Application("Finder");

appFinder.includeStandardAdditions = true;



let appSystemEvent = Application("System Events");

appSystemEvent.includeStandardAdditions = true;



//アプリケーションフォルダ

let strApplicationDirPath = appFinder.pathTo("applications folder",{from:"system domain"}).toString();

console.log(strApplicationDirPath)




//System eventを使った例

var strAcrobatDirPath = appSystemEvent.folders[strApplicationDirPath'/Adobe Acrobat DC'].posixPath();

console.log(strAcrobatDirPath)



//Pathとして結合

var strAcrobatDirPath = Path(strApplicationDirPath'/Adobe Acrobat DC');

console.log(strAcrobatDirPath)



//テキストとして結合

var strAcrobatDirPath = strApplicationDirPath'/Adobe Acrobat DC';

console.log(strAcrobatDirPath)




//NSURLを使った例

let ocidFilePathURL = refNSURL.fileURLWithPath('/Applications/Adobe Acrobat DC');

console.log(ocidFilePathURL.absoluteString.js)



//NSURLRFC形式をPOSIX PATH形式に

let ocidFilePath = ocidFilePathURL.path;

console.log(ocidFilePath.js)




|

その他のカテゴリー

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