hyperlink in documents

I’d like to know if it’s possible to import a link as a clickable string,

Ideally the string would be only the name of the file reference and not, it’s full URL, (which can be very long sometimes if the file is deeply nested)

set fileUrl to "file://" & posix path of (path to desktop as text) 

tell application "Notes"
	tell default account
		set res to make new note with properties {name:"Test", body:tfileUrl}
 	end tell
end tell

Like this?


set urlText to "επικοινωνήσετε"
set urlDescription to "Επικοινωνία"
set theURL to "https://macscripter.net/viewtopic.php?id=48007"
set noteTitle to "Test: add clickable link to the note"

set noteHTMLText to "<pre style=\"font-family:Helvetica,sans-serif;\">" & ¬
	"<a target=\"_blank\" href=" & theURL & ¬
	" data-linkname=" & urlDescription & " data-tag=\"GEN\" title=" & urlDescription & ¬
	" style=\"font-size: inherit; font-family: inherit; line-height: inherit;\">" & ¬
	urlText & "</a>" & ¬
	"</pre>"

tell application "Notes" to tell account (name of account 1)
	make new note at folder "Notes" with properties {name:noteTitle, body:noteHTMLText}
end tell

nice!

the script works and the formatting is right, however the Link is not clickable.
Paradoxically, the link is displayed as a clickable link and its property is its online url.

I tried to click on it with left click, then with right click to open the link with the contextual menu.
But the link does not do anything - the link looks like a link and is a link but behaves like a common string on click. Unbelievable.

MacOs 10.14.6
Script Editor 2.11
Applescript 2.7

  1. On my Mac it works with double-click, or with single left click when clicking not immediatelly
  2. Try replace my Greek texts with English. Maybe this causes the problem on your Mac
  3. Try replace font family Helvetica, sans serif with other. Maybe you have not this font on your Mac.

It works for me.
Thanks!
L.

I checked and tried all of the above, without results

Sorry the funny question, but what happens if you click the link, does the link launch the website in your default browser?

What’s the matter boy? I already told you that my link works. If you want to be specific, it opens the correct web page in my default browser.

KniazidisR’s script works for me as written. It also works for creating a link that’ll open a Finder window to my desktop, as per Joy’s original script.

But if the path contains characters which need to be percent-escaped in a URL, simply appending a POSIX path to “file://” won’t be good enough. The easiest recourse is probably to use System Events. I don’t know if it’ll solve the problem Joy’s having with KniazidisR’s solution, but at least the URL will be guaranteed correct:

set filePath to (path to desktop as text)
tell application "System Events" to set fileURL to URL of disk item filePath

@KniazidisR
Let’s be clear :
I am wondering why your solution doesn’t work, it seems to work nicely for all others
I didn’t lack you in respect and just told you what happens on my machine.
Anyway I hate if people get upset by little things like this and take it personally.

I’ve no reason to tell you something wrong just to bother you and myself, understood?

@Nigel Garvey
Yeah, you’re right but my “problem” is I wanted a nice formatting. It doesn’t work for me so I need to be happy with my own code.

Hello

I’m puzzled. I have no reason to doubt of what you wrote.
Alas, if I run the KniazidisR’s script, as well as the version using System Events to create the URL, everything looks OK minus the fact that the created link, which really reveal the dedicated contextual menu, doesn’t open the web page or the file.

May it be related to the used operating system which is necessarily 10.13.6 for me ?

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 10 novembre 2020 16:47:21

Joy and Yvan Koenig,

I didn’t find this script anywhere, but just looked at how Notes.app works with similar links on my computer. I advise you to do the same.

Because I can wiggle my brain, but I have no access to your computer. Therefore, you have to work here yourself. If, of course, you would like to really determine what is the matter. I already said that High Sierra is a super defective OS …

I tested with the script which you posted.
I got the results which I described.
It seems that you definitely refuse to admit that some users can’t install a system more recent than 10.13.6.

In the case of this thread, the problem is definitely not related to 10.13.6, Joy wrote that he is running 10.14.6

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 10 novembre 2020 20:51:38

Nobody doubts about your skills. Coding can be very time consuming, even if we know what we have to do. Even worse, if scripts don’t work, if they should.
I’ve had yet another issue with “Notes” but that was on 10.11.

https://macscripter.net/viewtopic.php?id=47490

There, you posted a very nice script, which helped me to get working links, , now. That is great !
Since I don’t know about html, css, Java and their like, extracting the right Syntax from your html code looks quite difficult. I played around but couldn’t figure out how to stitch head, the code I need and foot into a working syntax.
Would be nice to understand how to get a string bold 20, an empty line and a clickable link. This was basically the idea of my post.

I’m aware dealing with html requires different development tools to build a clear structured code, which I don’t have. Messing around with a sea of unstructured html code isn’t easy. And even if I had Atom or Visualcode, I wouldn’t have the knowledge to put together the right code :expressionless:

I can’t help here because I know about HTMLs only some basic things like you. It is better if you read some good book about HTML. Or…

At one time, I had a desire to study HTML in detail. But programming is a hobby for me, and my main job just doesn’t leave a lot of free time.

But I found an easy way to create colorful HTML without learning HTML. I just create a sheet in Microsoft Excel with text, pictures, hyperlinks, video clips, etc. I then export it as HTML, which can be copied and pasted into documents in other applications.