On 09/01/2023 10:19, Martin S Taylor wrote:
On 9 Jan 2023, Bruce Horrocks wrote (in article<[email protected]>):
I can insert a link to a file by a) Selecting "Add Link..." from
TextEdit's Edit menu; then b) dragging the file into the dialog
box which appears (this puts the URL of the file into the dialog
box); then c) adding "file://" before the URL in the dialog box.
There must be an easier way, surely?
Martin S Taylor
Drag the file into Safari and then drag the file:// URL from Safari
into TextEdit?
That's not a lot easier, really.
Ah, well, you asked for "easier" not "a lot easier" ;-)
Furthermore, if I select TextEdit's "Add Link..." I can at least link
it to words already in the document. So, for example, if the words
"this picture" appear in the TextEdit document, I can select them,
"Add Link..." and the link is then linked to the words "this
picture", and not a great ugly URL in the middle of my text.
Try this bit of AppleScript. It will prompt for various permissions the
first time as it needs to use Accessibility to be able to type into
TextEdit.
-- start of script
-- Save this AppleScript as a .app file.
-- To use, highlight a word in TextEdit and then drop a file onto this
script in the Finder.
-- The highlighted word will be replaced with a link to the file that
was dropped.
on open someItems
set theItem to item 1 of someItems
tell application "TextEdit"
activate
tell application "System Events"
set theFileURL to URL of (theItem as alias)
keystroke "k" using command down
keystroke theFileURL
-- keystroke return
end tell
end tell
end open
-- end of script
The "keystroke return" line is commented out so you can see what text
will be behind the link before you press return. If you are confident
then you can uncomment the line and you can save yourself a keypress.
--
Bruce Horrocks
Surrey, England
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)