r/applescript • u/simplicity_123 • Aug 07 '24
Which part is needed change for save the result in Clipboard
tell application "Safari"
set tURL to (URL of front document) as text
if (tURL = "") then
set alertMsg1 to "There is no Safari web page available."
display alert alertMsg1 message "" as informational buttons {"OK"} default button 1
return
end if
set tTitle to (name of front document) as text
set tTitle to my replaceChars(tTitle, ":", "-")
set tPrompt to "Save .webloc file as..."
set uFilePath to (choose file name with prompt tPrompt default name tTitle) as text
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set tFileName to (last text item of uFilePath)
set tParentPath to (((text items 1 through ((count text items of uFilePath) - 1) of uFilePath) as text) & ":")
set AppleScript's text item delimiters to oldDelim
tell application "Finder" to make new internet location file to tURL at tParentPath with properties {name:tFileName} end tell
on replaceChars(srcText, oldChars, newChars)
if (srcText = "") or (oldChars = "") then return srcText
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to oldChars
set tList to (every text item of srcText)
set AppleScript's text item delimiters to newChars
set srcText to (tList as text)
set AppleScript's text item delimiters to oldDelim
return srcText
end replaceChars
Which part is needed change for save the result in Clipboard
but not choose to file to save
2
Upvotes
1
u/libcrypto Aug 07 '24
1
u/[deleted] Aug 08 '24 edited Aug 08 '24
The AppleScript source included in my subsequent comment will hopefully help you if you’ve struggled with getting Safari’s .webloc files to be compatible with any other application. In its present form, it does two things when you drop a .webloc file onto its icon. First, it copies the URL targeted by the .webloc to the clipboard in clear text so you can paste it into a URL field of any web browser, and second, it creates a Windows .url file targeting the same URL on your desktop. You can open that file in a text editor to see the URL or work with the file. If you don’t want to change your clipboard when you use the script, you can remove or comment (add “–” or “#” to the beginning) the following line:
set the clipboard to theURL