Combine file/folder path selection to windows link

By “one backslash”, I’m guessing that you are getting this for your Windows paths:

but would rather get this:

If that is the case, then simply modifying the text item delimiters statement on line 8 of the code should give you what you want:


set TID to AppleScript's text item delimiters
try
	set AppleScript's text item delimiters to linefeed & "\\\\"
	tell application "Finder" to set tmpPaths to "\\\\" & selection
	if tmpPaths is "\\\\" then display dialog "Nothing selected" buttons {"Cancel"} default button 1
	set AppleScript's text item delimiters to ":"
	tell (get tmpPaths's text items)
		set AppleScript's text item delimiters to "\\\\"
		set windowsPaths to it as text
	end tell
	set the clipboard to windowsPaths
end try
set AppleScript's text item delimiters to TID

If that is not what you are looking for, you’ll have to explain what you need more clearly.

Sorry, i think i didn’t explained it correctly. Your script works fine, but not from within Typinator.

Only when i use Typinator it only gives an "" as the result after typing the abbreviatipn. Nothing more just one backslash. The program somehow doesn’t handle this script the way it handles script 1.

Below a screenshot of typinator. It is the third abbreviation, so when typed ‘ppw’ it should execute the script (win2.applesript).

From what you describe, it appears that the problem is with the way Typinator is handling the results of the AppleScript script rather than with the script itself. I’m not sure I can help you with this.

Just to clarify a couple of points, are you using the script exactly as displayed on this website, or have you modified it in any way? Also, regarding the fact that Script 1 executes properly in Typinator, that script returns POSIX paths, which typically don’t contain any backslash characters, whereas Windows paths do contain backslash characters (as file component separators.) Is it possible that Typinator is treating the backslash characters as special metacharacters rather than simply as literal characters?

Yes i used it exactly as u posted it here.

I guess it looks like a limitation of typinator as the script functions normal in osx. I’ll try to contact them and find out if the problem is about the handling of the windows path.

I’ll get back here if find the solution.

Thanks so far!

The plot thickens…

I have been a longtime fan of the creator of Typinator (specifically their app PopChar that provides quick and easy access to the entire Unicode character set.) Out of curiosity, I downloaded a trial version of Typinator and tried to reproduce your situation exactly with the following steps:

(1) Created a script in Script Editor (which I presume you are using as your script editor) with the code from my last post
(2) Saved the script as a text file named win2.applescript in the /Users/[home folder name]/Library/Application Support/Typinator/Sets/Includes/Scripts/ folder
(3) Created an abbreviation named ppw for win2.applescript in Typinator
(4) Selected several files in the Finder
(5) Opened a text document and typed the letters ppw
(6) Typinator replaced ppw with a tab character (which I then deleted)
(6) Pressed Command-v (the “paste” keystroke combination) to paste the current clipboard contents
(7) Sure enough, the Windows paths were properly pasted to my document.

So it works on my end. I would suggest going through each of the steps above and see if you are doing something different in one or more of the steps.

Yes they make some really usefull apps, PopChar is also a fine app to use! Typinator is really handy because it let’s you precompose standard emails with variables in it.

I completely used it as you just described it. So it is true that you can use the paste command after typing the abbreviation (which only leaves a backslash character on my side). Only when the script is used in for example a complete textual email it doesn’t automatically enters the file path. When using the built in FinderSelection script (FinderSelection.applescript in includes folder) of typinator it automatically expands the complete path of the selection after typing the abbreviation.

So that is why I it thaught it had something to do with the expand function in Script 1?!

I’ve now changed it by adding the a keystroke after the script in typinator. See below:

{Scripts/win2.applescript}{key:⌘V}

It now only has three (\) backslashes at the beginning of the link instead of two (\). Not find the solution to fix this yet.

Don’t think that above should be the correct way to use (if you look at the way FinderSelection.applescript works) but if this is the only solution then it’s fine by me.

Just a couple of further questions:

(1) Do you want one or two backslash characters separating components in the Windows file paths? (Or do you want two at the start of the path, and one between subsequent path components?)

(2) Can you please describe step-by-step how you use Typinator in your textual emails and the behavior you would like to see? With a little bit of tweaking, we should be able to get your script to do exactly what you want.

(1)
Our windows links only need two backslashes at the beginning and the addition of the server name (which only needs to be added for windows). Only one backslash is now automatically placed extra at the beginning after typing the abbreviation (ppw), but that is not the problem of the script it is placed by typinator. We have two servers (SD and NT) which have 2 different internal ip-addresses, it it possible for the script to see on which server it copies the link and then add SD or NT before the link?

So it should be like this:
\DS\path\to\selection\ or \NT\path\to\selection\

Instead of this:
\\path\to\selection\ (the first backslash is added by typinator for i don’t know which reason)

The script needs to add ‘SD or NT’ (server name for windows), that depends on which server the link is copied from.

(2)
We are using a complete precomposed textual email which shows a link to the file or folder and some specifications which can be sent to the client.

So win2.applescript is part of the precomposed email.

I can also create 2 scripts for both servers. But if it’s possible to let the script see from which ip it is copying the link and let it add the correct addition (SD or NT) than it would be awesome.

I tweaked the script so that it should put two slashes only at the beginning of paths. Also, when you type ppw, the ppw should now be replaced by the paths without the need for a Command-v keystroke, so you should remove that keystroke from your Typinator entry:


set windowsPaths to ""
set TID to AppleScript's text item delimiters
try
	set AppleScript's text item delimiters to linefeed & "\\\\"
	tell application "Finder" to set tmpPaths to "\\\\" & selection
	if tmpPaths is "\\\\" then display dialog "Nothing selected" buttons {"Cancel"} default button 1
	set AppleScript's text item delimiters to ":"
	tell (get tmpPaths's text items)
		set AppleScript's text item delimiters to "\\"
		set windowsPaths to it as text
	end tell
end try
set AppleScript's text item delimiters to TID
return windowsPaths

I don’t have the experience with files on servers to answer that question, but it seems likely that adding a server prefix to the paths should be scriptable.

Thanks bmose, it works great now!
For now i’ll start with 2 scripts, with a fixed prefix for the link. So i tweaked the script a little:


set windowsPaths to ""
set TID to AppleScript's text item delimiters
try
	set AppleScript's text item delimiters to linefeed & "\\"
	tell application "Finder" to set tmpPaths to "\\" & selection
	if tmpPaths is "\\" then display dialog "Nothing selected" buttons {"Cancel"} default button 1
	set AppleScript's text item delimiters to ":"
	tell (get tmpPaths's text items)
		set AppleScript's text item delimiters to "\\"
		set windowsPaths to "\\\\SD" & it as text
	end tell
end try
set AppleScript's text item delimiters to TID
return windowsPaths

I’ll make the expand of the abbreviation choose to use script A or B. So it is working great now!

Thanks a lot!

I’ll try to figure out if there is an option to let the script see what server (ip-address) the link is coming from. I’ll post it here if i find out how.

Glad you’ve got it working.

I found an old post in which DJ Bazzie Wazzie and McUsr discuss a way to get server information from file references. A key to their approach is bash’s mount command, which returns descriptive information on all mounted servers. I’m happy to help you pursue this further if you’d like. In order to do so, I would need to see the value returned by the following command (with both Windows servers mounted):


do shell script "mount"

The only lines I would need to see are those referring to your Windows servers. Any remaining lines can be deleted. Of course, this is only if you want to pursue this further. Another option would be to email me via Messages.

Oh wow, yes if you see a possible solution there. I also saw that script you are referring to but i didn’t saw a possible solution in there yet.

Below is the requested info of the mounted servers. The servers have multiple server shares do you think you need them all or is it just the 2 different ip addresses? The servers are linux based (synology), not windows.

//user@192.168.100.25/SD%20Studio on /Volumes/SD Studio (afpfs, nodev, nosuid, mounted by user)
//user@192.168.100.20/NT%20Studio on /Volumes/NT Studio (afpfs, nodev, nosuid, mounted by user)

Let me know if you need something else?

It may not be necessary to use bash’s mount command but instead simply to get each item’s volume name from its Finder reference’s disk property. Give this a try. It is a first attempt that may need tweaking:


set windowsPaths to ""
set TID to AppleScript's text item delimiters
try
	set windowsPathsList to {}
	tell application "Finder"
		repeat with currRef in (get selection)
			set {volumeName, HFSPath} to {currRef's disk's name, currRef as text}
			if {volumeName} is in {"SD Studio", "NT Studio"} then
				set windowsPathPrefix to "\\\\" & volumeName's text 1 thru 2
				set AppleScript's text item delimiters to ":"
				tell (get HFSPath's text items)
					set AppleScript's text item delimiters to "\\"
					set end of windowsPathsList to windowsPathPrefix & it
				end tell
			end if
		end repeat
	end tell
	set AppleScript's text item delimiters to linefeed
	set windowsPaths to windowsPathsList as text
end try
set AppleScript's text item delimiters to TID
return windowsPaths

Good first shot! Only missing the backslash between SD and SD Studio.

\SDSD Studio\2021\

The only thing is that it doesn’t work with the other server shares that we have. Let me describe the situation.

Server SD 192.168.100.25 (add SD before links)

  • SD Studio
  • Share A
  • Share B
  • Share C

Server NT 192.168.100.20 (add NT before all links)

  • NT Studio
  • Share F
  • Share R
  • Share Y

‘Share’ is not the real name of the shares. Do you need the exact names of the server shares?

Yes, please provide the exact share names. And thank you for pointing out the missing backslash. That’s easily put back in, which will be done after getting the other share names.

Ok see below the share names.

Server SD (add SD before links)

  • SD Studio
  • SD Archive
  • Cloche Studio B

Server NT (add NT before all links)

  • NT Studio
  • 0920 Studio
  • 0920 Archive
  • Cloche Studio A

Let’s try this:


set windowsPaths to ""
set TID to AppleScript's text item delimiters
try
	set windowsPathsList to {}
	tell application "Finder"
		repeat with currRef in (get selection)
			set {volumeName, HFSPath, volumeID} to {currRef's disk's name, currRef as text, missing value}
			if {volumeName} is in {"SD Studio", "SD Archive", "Cloche Studio B"} then
				set volumeID to "SD"
			else if {volumeName} is in {"NT Studio", "0920 Studio", "0920 Archive", "Cloche Studio A"} then
				set volumeID to "NT"
			end if
			if volumeID ≠ missing value then
				set AppleScript's text item delimiters to ":"
				tell (get HFSPath's text items)
					set AppleScript's text item delimiters to "\\"
					set end of windowsPathsList to "\\\\" & volumeID & "\\" & it
				end tell
			end if
		end repeat
	end tell
	set AppleScript's text item delimiters to linefeed
	set windowsPaths to windowsPathsList as text
end try
set AppleScript's text item delimiters to TID
return windowsPaths

Works like a charm! :smiley:

Testing it over VPN. I’m gonna test this when i’m at the office monday, but i don’t foresee any problems.

Thank you a lot bmose!