WEBLOCファイルから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 "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
#############################
###ダイアログ
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 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
############UTIリスト
set listUTI to {"com.apple.web-internet-location"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
### ファイル選択時
set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
set strFilePath to (POSIX path of aliasFilePath) 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) isDirectory:false)
##
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidFilePathURL)
set ocidURL to ocidPlistDict's valueForKey:("URL")
set strURL to ocidURL as text
################################
##
################################
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 aliasIconPath to (POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ClippingText.icns") as alias
try
set strMes to "base64テキストです" as text
set recordResult to (display dialog strMes with title "bundle identifier" default answer strURL buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer)
on error
log "エラーしました"
return
end try
if "OK" is equal to (button returned of recordResult) then
set strReturnedText to (text returned of recordResult) as text
else if (gave up of recordResult) is true then
return "時間切れです"
else if button returned of recordResult is "クリップボードにコピー" then
try
set strText to text returned of recordResult as text
####ペーストボード宣言
set appPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidText to (refMe's NSString's stringWithString:(strURL))
appPasteboard's clearContents()
set boolDone to appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
on error
##予備
if boolDone = false then
tell application "Finder"
set the clipboard to strURL as text
end tell
return "キャンセル"
end if
end try
end if
| 固定リンク
「XML webloc」カテゴリの記事
- [webloc] weblocファイルからURLを取り出す PlistBuddy(2021.05.04)
- [webloc] weblocファイルからURLを取り出す System Events(2021.05.06)
- WEBページの選択範囲(テキスト限定)からフラグメントを作成してURLに整形する(2025.05.03)
- [org.microsoft.link-preview]Microsoft EdgeのURLコピーの形式(超便利:私がMicrosoft Edgeを使う理由)(2025.04.02)
- macOSのWebloc(インターネットロケーションファイル)からWindows用のURLファイル(インターネットショートカットファイル)を作成する(2024.12.09)