AppleScript NSURLBookmark

[URLByResolvingBookmarkData]BOOKMARKデータをURLにする


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

#!/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 scripting additions
property refMe : a reference to current application

##デスクトップ
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
##BOOKMARKにする
set listDone to (ocidDesktopDirPathURL's bookmarkDataWithOptions:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) includingResourceValuesForKeys:{refMe's NSURLCustomIconKey} relativeToURL:(missing value) |error|:(reference))
set ocdiBookMarkData to (item 1 of listDone)

##BOOKMARKをエイリアスファイルにする
set ocidSaveAliasFilePathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:("デスクトップのエイリアス")
#
set listResults to (refMe's NSURL's writeBookmarkData:(ocdiBookMarkData) toURL:(ocidSaveAliasFilePathURL) options:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) |error|:(reference))


##エイリアスファイルを読み込む
set listResults to refMe's NSURL's bookmarkDataWithContentsOfURL:(ocidSaveAliasFilePathURL) |error|:(reference)
set ocdiBookMarkData to (item 1 of listResults)

##BOOKMARKデータをURLにする
set listResponse to (refMe's NSURL's URLByResolvingBookmarkData:(ocdiBookMarkData) options:(refMe's NSURLBookmarkResolutionWithoutUI) relativeToURL:(missing value) bookmarkDataIsStale:(missing value) |error|:(reference))
set ocidBookMarkURL to (item 1 of listResponse)
log ocidBookMarkURL's absoluteString() as text

##BOOKMARK=エイリアスの参照先URLを取得
set listResponse to (refMe's NSURL's URLByResolvingAliasFileAtURL:(ocidSaveAliasFilePathURL) options:(refMe's NSURLBookmarkResolutionWithoutUI) |error|:(reference))
set ocidBookMarkURL to (item 1 of listResponse)
log ocidBookMarkURL's absoluteString() as text



|

[NSKeyedUnarchiver]com.apple.LSSharedFileListのBookMarkデータを表示(macOS14対応)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# com.apple.LSSharedFileListのBookMarkデータを表示します
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()

###################################
#####ファイル選択ダイアログ
###################################
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
activate
  end tell
else
  tell current application
activate
  end tell
end if
####ダイアログを出す
set listUTI to {"com.apple.property-list", "dyn.ah62d4rv4ge81g3xqgq"} as list
set aliasFilePath to (choose file with prompt "plistファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
####入力ファイルパス
set strFilePath to POSIX path of aliasFilePath
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) isDirectory:false)
set strExtensionName to (ocidFilePathURL's pathExtension()) as text

###################################
#####処理分岐
###################################
if strExtensionName is "plist" then
  # DICTに読み込んで
  set listResponse to refMe's NSDictionary's alloc()'s initWithContentsOfURL:(ocidFilePathURL) |error|:(reference)
  set ocidPlistDict to (item 1 of listResponse)
else if strExtensionName is "sfl3" then
  # NSDataに読み込んで
  set ocidReadData to refMe's NSData's dataWithContentsOfURL:(ocidFilePathURL)
  # unarchivedObjectOfClassで解凍する
  set listResponse to refMe's NSKeyedUnarchiver's unarchivedObjectOfClass:((refMe's NSObject)'s class) fromData:(ocidReadData) |error|:(reference)
  set ocidPlistDict to (item 1 of listResponse)
  if ocidPlistDict = (missing value) then
return "解凍に失敗しました"
  end if
end if

###################################
#####
###################################
set ocidItemsArray to (ocidPlistDict's objectForKey:("items"))
repeat with itemsArrayDict in ocidItemsArray
  set ocidBookMarkData to (itemsArrayDict's objectForKey:("Bookmark"))
  #BOOKMarkデータの解凍
  set listResponse to (refMe's NSURL's URLByResolvingBookmarkData:(ocidBookMarkData) options:(refMe's NSURLBookmarkResolutionWithoutUI) relativeToURL:(missing value) bookmarkDataIsStale:(missing value) |error|:(reference))
  set ocidBookMarkURL to (item 1 of listResponse)
log ocidBookMarkURL's absoluteString() as text
  
end repeat



|

デスクトップにiCloudDriveのエイリアスを作る(アイコン付き)

Screen-20231106-150755

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
# デスクトップにクラウドドライブのエイリアスを作ります
# Finderでは『iCloud Drive』と表示されていますが
# フォルダ名は『Mobile Documents』なので留意
#
# 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 appFileManager to refMe's NSFileManager's defaultManager()

####################################
###ドコ?に作る?
set strAddAliasFilePath to ("~/Desktop/iCloudDrive") as text

###アイコンどうする?
set boolSetIcon to true as boolean
###アイコン付きの場合
if boolSetIcon is true then
  ###iCloudDrive.icnsのパス
  set strIconFilePath to "/System/Library/PrivateFrameworks/iCloudDriveCore.framework/Versions/A/Resources/iCloudDrive.icns" as text
end if

####################################
####エイリアスが作られる場所
set ocidAddAliasFilePathStr to refMe's NSString's stringWithString:(strAddAliasFilePath)
set ocidAddAliasFilePath to ocidAddAliasFilePathStr's stringByStandardizingPath
set ocidAddAliasFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidAddAliasFilePath) isDirectory:false
set strAddAliasFilePathURL to ocidAddAliasFilePathURL's |path|() as text

###ディレクトリを作る必要があれば作る
set ocidAddAliasDirFilePathURL to ocidAddAliasFilePathURL's URLByDeletingLastPathComponent()
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidAddAliasDirFilePathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)

####################################
####エイリアスの元ファイル
####################################
set ocidUserLibraryPathArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidUserLibraryPathURL to ocidUserLibraryPathArray's objectAtIndex:0
set ocidiCloudDriveURL to ocidUserLibraryPathURL's URLByAppendingPathComponent:"Mobile Documents"

####################################
#### エイリアスを作る
####################################
set listDone to (ocidiCloudDriveURL's bookmarkDataWithOptions:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) includingResourceValuesForKeys:{refMe's NSURLCustomIconKey} relativeToURL:(missing value) |error|:(reference))
set ocdiBookMarkData to (item 1 of listDone)

set listResults to (refMe's NSURL's writeBookmarkData:(ocdiBookMarkData) toURL:(ocidAddAliasFilePathURL) options:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) |error|:(reference))
log item 1 of listResults
####################################
#### アイコンを付与
####################################
if boolSetIcon is true then
  ###ICONパス
  set ocidIconPathStr to refMe's NSString's stringWithString:(strIconFilePath)
  set ocidIconPath to ocidIconPathStr's stringByStandardizingPath()
  set ocidIconPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidIconPath) isDirectory:false)
  ##アイコン用のイメージデータ取得
  set ocidImageData to (refMe's NSImage's alloc()'s initWithContentsOfURL:(ocidIconPathURL))
  ###NSWorkspace初期化
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  ###アイコン付与
  set boolAddIcon to (appSharedWorkspace's setIcon:(ocidImageData) forFile:(ocidAddAliasFilePath) options:(refMe's NSExclude10_4ElementsIconCreationOption))
end if

return

|

[NSURLBookmarkCreationOptions]8bit値が戻り値


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

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


log (refMe's NSURLBookmarkCreationPreferFileIDResolution) as integer (*256*)
log (refMe's NSURLBookmarkCreationMinimalBookmark) as integer (*512*)
log (refMe's NSURLBookmarkCreationSuitableForBookmarkFile) as integer (*1024*)
log (refMe's NSURLBookmarkCreationWithSecurityScope) as integer (*2048*)
log (refMe's NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess) as integer (*4096*)
log (refMe's NSURLBookmarkCreationWithoutImplicitSecurityScope) as integer (*5.36870912E+8*)


log (refMe's NSURLBookmarkResolutionWithoutUI) as integer (*256*)
log (refMe's NSURLBookmarkResolutionWithoutMounting) as integer (*512*)
log (refMe's NSURLBookmarkResolutionWithSecurityScope) as integer (*1024*)
log (refMe's NSURLBookmarkResolutionWithoutImplicitStartAccessing) as integer (*32768*)



log (refMe's NSURLBookmarkCreationPreferFileIDResolution) / 256 as integer (*1*)
log (refMe's NSURLBookmarkCreationMinimalBookmark) / 256 as integer (*2*)
log (refMe's NSURLBookmarkCreationSuitableForBookmarkFile) / 256 as integer (*4*)
log (refMe's NSURLBookmarkCreationWithSecurityScope) / 256 as integer (*8*)
log (refMe's NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess) / 256 as integer (*16*)
log (refMe's NSURLBookmarkCreationWithoutImplicitSecurityScope) / 256 as integer (*2097152*)


log (refMe's NSURLBookmarkResolutionWithoutUI) / 256 as integer (*1*)
log (refMe's NSURLBookmarkResolutionWithoutMounting) / 256 as integer (*2*)
log (refMe's NSURLBookmarkResolutionWithSecurityScope) / 256 as integer (*4*)
log (refMe's NSURLBookmarkResolutionWithoutImplicitStartAccessing) / 256 as integer (*128*)






|

アプリケーションのエイリアスをデスクトップに作成する


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

#!/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 "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application

###初期化
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set appFileManager to refMe's NSFileManager's defaultManager()
#####ダイアログを前面に
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
###ダイアログ
set listUTI to {"com.apple.application-bundle"}
###アプリケーションディレクトリ
set ocidUserLibraryPathArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationDirectory) inDomains:(refMe's NSUserDomainMask))
###URL
set ocidAppDirPathURL to ocidUserLibraryPathArray's firstObject()
set aliaAppDirPath to (ocidAppDirPathURL's absoluteURL()) as alias
set aliasAppPath to (choose file with prompt "対象のアプリケーションを選んでください" default location (aliaAppDirPath) of type listUTI with invisibles without showing package contents and multiple selections allowed) as alias
###パス
set strAppPath to POSIX path of aliasAppPath
set ocidAppPathStr to refMe's NSString's stringWithString:(strAppPath)
set ocidAppPath to ocidAppPathStr's stringByStandardizingPath()
set ocidAppPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidAppPath) isDirectory:true)

####アプリのアイコンパス
###バンドル取得
set ocidAppBundle to refMe's NSBundle's bundleWithURL:(ocidAppPathURL)
###情報取得
set ocidInfoDict to ocidAppBundle's infoDictionary
###アプリケーション名
set ocidBundleDisplayName to ocidInfoDict's valueForKey:("CFBundleDisplayName")
###CFBundleDisplayNameが無い場合
if ocidBundleDisplayName = (missing value) then
  log "CFBundleName名を使います"
  set ocidBundleDisplayName to ocidInfoDict's valueForKey:("CFBundleName")
end if
###アイコン名
set strIconFileName to (ocidInfoDict's valueForKey:("CFBundleIconFile")) as text
###ICONのURLにして
set strPath to ("Contents/Resources/" & strIconFileName) as text
set ocidIconFilePathURL to ocidAppPathURL's URLByAppendingPathComponent:(strPath) isDirectory:false
###拡張子の有無チェック
set strExtensionName to (ocidIconFilePathURL's pathExtension()) as text
if strExtensionName is "" then
  set ocidIconFilePathURL to ocidIconFilePathURL's URLByAppendingPathExtension:"icns"
end if
###パス
set ocidIconFilePath to ocidIconFilePathURL's |path|
###ICONファイルが実際にあるか?チェック
set boolExists to appFileManager's fileExistsAtPath:(ocidIconFilePath)
###ICONがみつかない時用にデフォルトを用意する
if boolExists is false then
  set strIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericQuestionMarkIcon.icns"
  set ocidIconPathstr to refMe's NSString's stringWithString:(strIconPath)
  set ocidIconPath to ocidIconPathstr's stringByStandardizingPath()
  set ocidIconFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidIconPath) isDirectory:false)
  set aliasIconPath to ocidIconFilePathURL's absoluteURL() as alias
else
  set aliasIconPath to ocidIconFilePathURL's absoluteURL() as alias
end if
###########################
##アイコン用のイメージデータ取得
set ocidImageData to (refMe's NSImage's alloc()'s initWithContentsOfURL:(ocidIconFilePathURL))
###########################
###bookmark エイリアスデータ
set listBookMarkNSData to (ocidAppPathURL's bookmarkDataWithOptions:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) includingResourceValuesForKeys:{refMe's NSURLCustomIconKey} relativeToURL:(missing value) |error|:(reference))
set ocdiBookMarkData to (item 1 of listBookMarkNSData)

###########################
###デスクトップ
set ocidDesktopPathArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopPathURL to ocidDesktopPathArray's firstObject()
set ocidDesktopPath to ocidDesktopPathURL's |path|
###ブックマーク作成先
set ocidBookMarkPathURL to ocidDesktopPathURL's URLByAppendingPathComponent:(ocidBundleDisplayName) isDirectory:false
set ocidBookMarkPath to ocidBookMarkPathURL's |path|
####エイリアスを作る
set listResults to (refMe's NSURL's writeBookmarkData:(ocdiBookMarkData) toURL:(ocidBookMarkPathURL) options:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) |error|:(reference))

###########################
###アイコン付与

set boolAddIcon to appSharedWorkspace's setIcon:(ocidImageData) forFile:(ocidBookMarkPath) options:(refMe's NSExclude10_4ElementsIconCreationOption)
###選択して表示
set boolSelectFileResults to appSharedWorkspace's selectFile:(ocidBookMarkPath) inFileViewerRootedAtPath:(ocidDesktopPathURL)


|

エイリアス作成とアイコン付与


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

#!/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 scripting additions
property refMe : a reference to current application
###初期化
set appFileManager to refMe's NSFileManager's defaultManager()
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
###########################
###アプリケーションディレクトリ(ユーザーアプリケーション)
set ocidUserApplicationPathArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidApplicationDirPathURL to ocidUserApplicationPathArray's firstObject()
set ocidApplicationDirPath to ocidApplicationDirPathURL's |path|
###フォルダ作る
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidApplicationDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
###/users/XXXXX/Applications/Finderのエイリアス
set ocidBookMarkPathURL to ocidApplicationDirPathURL's URLByAppendingPathComponent:("Finder Applications") isDirectory:true
set ocidBookMarkPath to ocidBookMarkPathURL's |path|
###########################
###コアサービス
set ocidCoreServiceDirPathArray to (appFileManager's URLsForDirectory:(refMe's NSCoreServiceDirectory) inDomains:(refMe's NSSystemDomainMask))
set ocidCoreServiceDirPathURL to ocidCoreServiceDirPathArray's firstObject()
###Finder
set ocidFinderFilePathURL to ocidCoreServiceDirPathURL's URLByAppendingPathComponent:("Finder.app/Contents/Applications") isDirectory:true
###ICON
set ocidFinderIconFilePathURL to ocidCoreServiceDirPathURL's URLByAppendingPathComponent:("Finder.app/Contents/Resources/Finder.icns") isDirectory:true
###########################
###bookmark エイリアスデータ
set listBookMarkNSData to (ocidFinderFilePathURL's bookmarkDataWithOptions:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) includingResourceValuesForKeys:{refMe's NSURLCustomIconKey} relativeToURL:(missing value) |error|:(reference))
set ocdiBookMarkData to (item 1 of listBookMarkNSData)
####エイリアスを作る
set listResults to (refMe's NSURL's writeBookmarkData:(ocdiBookMarkData) toURL:(ocidBookMarkPathURL) options:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) |error|:(reference))
###########################
###アイコン付与
set ocidImageData to (refMe's NSImage's alloc()'s initWithContentsOfURL:(ocidFinderIconFilePathURL))
set boolAddIcon to appSharedWorkspace's setIcon:(ocidImageData) forFile:(ocidBookMarkPath) options:(refMe's NSExclude10_4ElementsIconCreationOption)
###選択して表示
set boolSelectFileResults to appSharedWorkspace's selectFile:(ocidBookMarkPath) inFileViewerRootedAtPath:(ocidApplicationDirPath)


|

[writeBookmarkData]Finderエイリアスを作成する

一般的には

tell application "Finder"

set aliasDesktopPath to path to desktop folder from user domain
set aliasDownlordFolder to path to downloads folder from user domain

make new alias to aliasDownlordFolder at aliasDesktopPath
end tell


#!/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 objFileManager to refMe's NSFileManager's defaultManager()

#####デスクトップフォルダ
set ocidDesktopDirPath to (objFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidDesktopDirPath's objectAtIndex:0
####デスクトップに作るエイリアスの名前
set ocidAiliasURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:"Downloads"
set ocidAiliasPath to ocidAiliasURL's |path|()

####有無確認
set boolDirExists to (objFileManager's fileExistsAtPath:ocidAiliasPath isDirectory:false)
if boolDirExists is false then
###ダウンロードフォルダ
set ocidUserDownloadsPath to (objFileManager's URLsForDirectory:(refMe's NSDownloadsDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidUserDownloadsURL to ocidUserDownloadsPath's objectAtIndex:0

####エイリアスデータの取得
set listBookMarkNSData to (ocidUserDownloadsURL's bookmarkDataWithOptions:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) includingResourceValuesForKeys:{refMe's NSURLCustomIconKey} relativeToURL:(missing value) |error|:(reference))
set ocdiBookMarkData to (item 1 of listBookMarkNSData)

####エイリアスを作る
set listResults to (refNSURL's writeBookmarkData:ocdiBookMarkData toURL:ocidAiliasURL options:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) |error|:(reference))

end if

|

choose default locationに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
property refNSString : a reference to refMe's NSString
property refNSURL : a reference to refMe's NSURL

########################################
#######前準備
##このファイルへのパスとコンテナ
tell application "Finder"
set aliasPathToMe to (path to me) as alias
set aliasPathToMeDir to (container of aliasPathToMe) as alias
end tell
set strPathToMePath to (POSIX path of aliasPathToMe) as text
set strPathToMeDirPath to (POSIX path of aliasPathToMeDir) as text
########################################
#######ファイル選択
---プロンプトの文言改行が使えます\nを入れます
set theWithPrompt to "ファイルを選択してください"
---ファイル選択ダイアログのデフォルトのディレクトリ
set aliasDefaultLocation to path to desktop folder from user domain
set theFileTypeList to {"public.item"}
---ダイアログを出して選択されたファイルは「open」に渡す
set aliasFilePath to (choose file default location aliasDefaultLocation ¬
with prompt theWithPrompt ¬
of type theFileTypeList ¬
invisibles false ¬
without showing package contents and multiple selections allowed)
####入力ファイル関連
set strFilePath to POSIX path of aliasFilePath as text
###NSストリングに
set ocidFilePath to refNSString's stringWithString:strFilePath
###NSURL
set ocidFilePathURL to refNSURL's fileURLWithPath:ocidFilePath
##ファイル名取得
set strFileName to (ocidFilePathURL's lastPathComponent) as text
####保存先をこのロケーションで
set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
set aliasContainerDirPath to ocidContainerDirPathURL as alias
####
set listURLArray to refNSURL's URLByResolvingAliasFileAtURL:ocidContainerDirPathURL options:(refMe's NSURLBookmarkResolutionWithoutUI) |error|:(reference)
set ociddirURL to listURLArray's item 1
(*
NSURLBookmarkResolutionOptions
NSURLBookmarkResolutionWithoutUI:8
NSURLBookmarkResolutionWithoutMounting:9
NSURLBookmarkResolutionWithSecurityScope:10
NSURLBookmarkResolutionWithoutImplicitStartAccessing:15
*)

########################################
######出力ファイル
##ファイル名
set strFileName to (strFileName & ".html") as text
set aliasSaveFilePath to choose file name with prompt "htmlのファイル名を付けてください" default name strFileName default location (aliasContainerDirPath)
###パス
set strSaveFilePath to POSIX path of aliasSaveFilePath as text
###NSストリングに
set ocidSaveFilePath to refNSString's stringWithString:strSaveFilePath
###NSURL
set ocidSaveFilePathURL to refMe's NSURL's fileURLWithPath:ocidSaveFilePath
##拡張子
set strFileExtension to (ocidFilePathURL's pathExtension) as text
###拡張子つけ忘れ対策
if strFileExtension is not "html" then
set strSaveFilePath to (POSIX path of aliasSaveFilePath & ".html") as text
end if

|

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat Dialog Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat python Acrobat Reader Acrobat Sequ Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Apple AppleScript AppleScript Guide AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes 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 Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray 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 NSFont AppleScript NSFontManager 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 NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange 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 NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript Plist System Events 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 Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV 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 SVG AppleScript XML TTML AppleScript XML webloc AppleScript YouTube AppleScript Zero Suppress Applications Barcode OnLine Tools CityCode Design iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom