Monday, December 9, 2019

#1 2019-11-18 12:16:01 pm

FreddieMac
Member
Registered: 2019-11-14
Posts: 6

Help me generate hyperlinks for email use please...

Hello,

On a daily basis with 30 or more emails, I have to insert links to files
for our groups.
My process is as follows:
From the Mac finder copy the pathname into the clipboard.
Paste the path into an excel doc: "filesystem_location_generator"
which then generates the two links to be pasted into Outlook.
In Outlook I command_option_shift paste so that it blesses it as a hyperlink.
At the end of the day I become an ogre and slimy toads come out of my mouth ugrh$%@!

I wish I could do the above in a smarter way ideally from
Clipboard pathname to Outlook hyperlinks bypassing Excel.

Can someone point me to a link or a source?
I am adventurous with scripting and I use Terminal a little.
I prefer scripting as opposed to an app or a standalone plugin.

Thanks.

Model: iMac
AppleScript: 2.7
Browser: Safari 537.36
Operating System: macOS 10.12

Offline

 

#2 2019-11-18 07:38:16 pm

CK
Member
From:: UK
Registered: 2018-11-04
Posts: 109

Re: Help me generate hyperlinks for email use please...

How come you can't just copy the files in Finder, with Cmd-C, then do a straight paste into your Outlook with Cmd-V, which in many apps would insert the files as clickable icons in the body of the email ?

What happens if you try that, i.e. what is the specific result ?

And what is Excel actually doing because I've got no sense of what is occurring there.


To be brief, the macOS clipboard will hold many different data representations from each singular copying action, which allows the receiving application to choose what is (suppose to be) the most suitable data type to use when one triggers a paste.  This is what allows one to copy a file in Finder, which will get pasted as a file in Finder, but as a plain text posix path in Terminal and Script Editor, and then as a picture in Preview (if the file was, say, a jpeg or png file).

So instead of copying pathnames from Finder, try copying the files and see what Outlook decides to do with them.

Offline

 

#3 2019-11-19 11:40:39 am

FreddieMac
Member
Registered: 2019-11-14
Posts: 6

Re: Help me generate hyperlinks for email use please...

Thank you for the reply.

Your solution is precisely what I'm trying to avoid.

What I'm looking for is a script that will automatically generate hypertext urls for both mac and windows without doing a whole lotta typing and linking pictures with servers.
i.e. Windows link:
\\server_name\location....
i.e. Mac link:
\\server_name\location....
file:///Volumes/server_name/location...

Getting those two clickable links is a pita doing it manually.

Excel simply generates the windows version of the link with the slashes backwards ready to be pasted into outlook.

Thanks.

Offline

 

#4 2019-11-23 12:52:43 am

CK
Member
From:: UK
Registered: 2018-11-04
Posts: 109

Re: Help me generate hyperlinks for email use please...

Am I understanding you correctly that you would like a hyperlink in an email such that if the email is viewed in Windows, it links to a remote file with path

\\server\folder\file.ext

and when the email is view in Windows, it links the same remote file with path

file:///Volumes/server/folder/file.ext

You said Excel generates the Windows-style link, which you're doing within macOS's Finder.  After Excel does its thing, and you move to your email in Outlook, what text gets pasted when you Cmd-Option-Shift paste it ?  Presumably this text appears as a blue, underlined, clickable link.  For comparison, what text gets pasted when you simply Cmd-V ? 

With the clickable link, when you right-click it to bring up a context menu, there should be a menu item to Copy Link to Clipboard (or something similar-sounding).  When you select this, and then paste it into a plain text document with Cmd-V, what gets pasted ?

If you could use a real file path, and the same one for each of those questions above, that'd be really helpful to provide insight into what is actually happening.

Lastly, with the clipboard containing those Excel generated links that you Cmd-Option-Shift paste into Outlook, what is returned in Script Editor when you execute the following AppleScript:

Applescript:

clipboard info

Last edited by CK (2019-11-23 12:53:38 am)

Offline

 

#5 2019-11-26 05:34:35 pm

FreddieMac
Member
Registered: 2019-11-14
Posts: 6

Re: Help me generate hyperlinks for email use please...

if followed by copy as path name from the finder, Command -V will paste the path text location. No url.
Command-V from a picture copy will simply copy the picture. No url.
I'm not sure what your last question is??? (Open this Scriplet in your Editor:
clipboard info)

In a nutshell, I am looking for a url path generator. I know there are helpers and plugins and standalone apps I can use, unfortunately in my work environment I'm not allowed to install unauthorized apps. Which is why I am on this forum.
Ideally I would like an automator workflow or a javascript applet that would generate Mac/Win urls.

I believe my question is a simple one...

Thanks.

Offline

 

#6 2019-11-27 09:31:02 am

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 464

Re: Help me generate hyperlinks for email use please...

I'm pretty sure your script would be easy to write. These forums are aimed at helping people with scripts, not just writing scripts from scratch... generally, posters should be posting their attempts at code for people to help with.

But I'm guessing this is like a 5 minute scripting job someone might actually just write for you for the heck of it.

However, so far, attempts to get specific information from you about what you actually need the script to do are not yielding the required information.

If you provide an example of an example file path you'd copy in Finder (and how you're getting that - are you just using [command] + C to copy the file, or is it right-click + option + "Copy [filename] as Pathname?), and then give us what's actually on the clipboard that you paste into Outlook for that file, you might get some help.


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

#7 2019-11-30 09:29:06 pm

CK
Member
From:: UK
Registered: 2018-11-04
Posts: 109

Re: Help me generate hyperlinks for email use please...

FreddieMac wrote:

I believe my question is a simple one...

Don't put yourself down like that.  If it were simple, you wouldn't be asking for help.  But no one is as good as explaining what they mean as they think they are in their head, and describing something three times using the same words rarely adds clarity.

Good luck with it.

Offline

 

#8 2019-12-06 05:37:17 pm

FreddieMac
Member
Registered: 2019-11-14
Posts: 6

Re: Help me generate hyperlinks for email use please...

t.spoon wrote:

I'm pretty sure your script would be easy to write. These forums are aimed at helping people with scripts, not just writing scripts from scratch... generally, posters should be posting their attempts at code for people to help with.

But I'm guessing this is like a 5 minute scripting job someone might actually just write for you for the heck of it.

However, so far, attempts to get specific information from you about what you actually need the script to do are not yielding the required information.

If you provide an example of an example file path you'd copy in Finder (and how you're getting that - are you just using [command] + C to copy the file, or is it right-click + option + "Copy [filename] as Pathname?), and then give us what's actually on the clipboard that you paste into Outlook for that file, you might get some help.



Thanks.

My process is as follows:
1_in the finder I option-control-clik to copy as pathname on tiff files.
2_In Excel I have a “filesystem location generator” converter in which I paste the mac path name. The generator spits out the windows/mac paths:
\\server_name\….for Windows
file:///Volumes/server_name… for Mac
3_I then copy each link and command-option-shift paste them into outlook to generate hyperlinks for our clients to browse on our local server.

Is there a script or tutorial for this task?

Offline

 

#9 2019-12-06 07:22:00 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6065

Re: Help me generate hyperlinks for email use please...

FreddieMac wrote:

spits out



Could you be a bit more specific?

I then copy each link



Separately?

Sorry if it sounds like we're being pedantic, but this is one of those cases where you clearly know what's going on, but the rest of us are working in the dark.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#10 2019-12-06 10:14:05 pm

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 464

Re: Help me generate hyperlinks for email use please...

OK, well, I didn't even quite follow your instructions as best I understand them. There was still some ambiguity, but I just thought "Look, he wants to paste Windows and Mac links to the selected finder file into Outlook. I'll just do that the way I'd do it if I wanted it for myself."

So when there's a Finder selection, this pastes clickable links for whatever is selected in Finder into Outlook. It supports selecting multiple files and/or directories at once and pastes in both links for all selected items.

However:

I decided to paste in HTML clickable URIs, so it can be a link with the filename. But doing it that way doesn't support UNC Windows file paths, which is the format you showed:

\\server_name\….


it has to be URI's. And I don't have a Windows machine to test on. I have Parallels, and an ancient XP VM, but I tried to fire it up for the first time in years and my computer instant rebooted... so apparently it doesn't like that anymore.

So I just followed what Microsoft claims is a valid Windows file URI here:
https://blogs.msdn.microsoft.com/ie/200 … n-windows/
With 0 testing. What actually happens when you click that link on a PC, I don't know.

I'd recommend running the script from a command key, such as with FastScripts:
https://red-sweater.com/fastscripts/

But you can just select item(s) in Finder, and then run it from the script menu or switch to the script in Script Editor and press "run."

The Mac links it generates and pastes work for me.

Hope this is helpful to you or others who find it. Found an interesting hack here:
https://stackoverflow.com/questions/112 … -type-data
That I incorporated to get the clipboard in the right format.

Applescript:


use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Finder"
   set selectedFiles to the selection
   -- repeat loop will expect a list; if it's a single file, make it a list
   if class of selectedFiles is not list then set selectedFiles to {selectedFiles}
   -- generate standard HTML links for Windows and MacOS for each file
   set htmlLinks to ""
   repeat with aFile in selectedFiles
       -- use file name for link text
       set fileName to the name of aFile
       set filePath to POSIX path of (aFile as alias)
       -- Doc says windows URI's want spaces converted, MacOS doesn't seem to care
       set escSpacefilePath to my replace_chars(filePath, " ", "%20")
       -- Make Windows URI
       set {delimitHolder, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
       set windowsURI to "file://" & text items 3 through end of escSpacefilePath as text
       set AppleScript's text item delimiters to delimitHolder
       -- Make URI into HREF
       set windowsHREF to my make_href(fileName, windowsURI)
       -- Make Mac URI
       set macURI to "file://" & filePath
       -- Make Mac URI into HREF
       set macHREF to my make_href(fileName, macURI)
       -- If we're doing multiple files, put a blank line separating each set of links
       if htmlLinks ≠ "" then set htmlLinks to htmlLinks & "<br><br>"
       -- Differentiate the links in text and add returns
       set htmlLinks to htmlLinks & "Windows Link: " & windowsHREF & "<br>Mac Link: " & macHREF
   end repeat
end tell
-- Convert from standard HTML to Hex encoded URL clipboard format
set outputText to generate_hex_link(htmlLinks)
set the clipboard to outputText
-- activate Outlook and paste
tell application "Microsoft Outlook" to activate
tell application "System Events"
   tell application process "Microsoft Outlook"
       keystroke "v" using command down
   end tell
end tell

on make_href(linkText, theURL)
   set theHREF to "<a href=\"" & theURL & "\">" & linkText & "</a>"
end make_href

on generate_hex_link(html)
   -- hex encode
   set theHEX to do shell script "echo " & quoted form of html & " | hexdump -ve '1/1 \"%.2x\"'"
   -- need to metascript to make "data" be recognized correctly combined with hex
   set subscriptText to "return «data HTML" & theHEX & "»"
   set hexLink to run script subscriptText
   return hexLink
end generate_hex_link

-- Generic find and replace functionality
on replace_chars(this_text, search_string, replacement_string)
   set TID to AppleScript's text item delimiters
   set AppleScript's text item delimiters to the search_string
   set the item_list to every text item of this_text
   set AppleScript's text item delimiters to the replacement_string
   set this_text to the item_list as string
   set AppleScript's text item delimiters to TID
   return this_text
end replace_chars

Last edited by t.spoon (2019-12-06 10:28:29 pm)


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

#11 Today 11:10:16 am

FreddieMac
Member
Registered: 2019-11-14
Posts: 6

Re: Help me generate hyperlinks for email use please...

Shane Stanley wrote:
FreddieMac wrote:

spits out



Could you be a bit more specific?

I then copy each link



Separately?

Sorry if it sounds like we're being pedantic, but this is one of those cases where you clearly know what's going on, but the rest of us are working in the dark.



Sorry. I see how it can be vague...
Excel converts the Mac path into windows and mac file location with the slashes properly formatted.
Then EACH link is copied and pasted into Outlook.

Offline

 

#12 Today 04:52:30 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6065

Re: Help me generate hyperlinks for email use please...

You can create the Mac links like this:

Applescript:

set theFile to (the clipboard as «class furl») as text
tell application id "com.apple.systemevents" -- System Events.app
   set theURL to URL of disk item theFile
end tell
set the clipboard to theURL

And assuming you're always dealing with files on remote servers, you can generate the Windows path like this:

Applescript:

set theFile to (the clipboard as «class furl») as text
tell application id "com.apple.systemevents" -- System Events.app
   set theURL to URL of disk item theFile
end tell
set winRef to text 17 thru -1 of theURL
set {saveTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {"/"}}
set winTemp to text items of winRef
set AppleScript's text item delimiters to {"\\"}
set winRef to "\\\\" & (winTemp as text)
set AppleScript's text item delimiters to saveTID
set the clipboard to winRef


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)