Clipboard text formating

The AppleScript creates a set of folders at the folder path stored clipboard path.
This works well when the path is copied using the contextual finder menu Copy as Pathname.

On the other hand, the AppleScript fails when the clipboard path originates with the Adobe Bridge Application Copy path function.

The following manual workaround does work with the Adobe Bridge and might hint at a solution

  1. Copy the folder path using the Adobe Bridge Application
  2. Paste the path into a text file
  3. Reselect the path
  4. Copy to clipboard
  5. Execute AppleScript

Something happens in this workaround that validates the clipboard text for the AppleScript.

Can an AppleScript take the text that is the clipboard and reformat it to the default clipboard text? The idea here is to strip off any text formatting introduced by the Bridge application.

Here is the line from the Bridge Application script that copies the path to the clipboard.

app.system('echo '+ thumbs[0].spec.fsName + ‘|pbcopy’);

What AppleScript, what workaround… Why do not simply


set thePath to the clipboard as string

Assuming the clipboard contains Posix path in plain text form or RTF form, you can create folder this way:


set posixPath to the clipboard as string
set hfsPath to posixPath as POSIX file as text

tell application "Finder"
	make new folder at folder hfsPath with properties {name:"myNewFolder"}
end tell

Thanks, your solution works when the clipboard path originates with the right-click contextual menu. When the path originates with the Bridge app the apple script produces the following"

error “Finder got an error: Can’t get folder "Macintosh HD:Users:Shared:WEB
".” number -1728 from folder "Macintosh HD:Users:Shared:WEB
"

Probably the path created with the Bridge app is not a Posix path in plain-text form or RTF path. Honestly, I am not sure what type of path is created when using the Adobe Bridge app to copy to the clipboard.
The path from the Bridge app looks like a conventional path when copied to a txt file.
For example: /Users/Shared/WEB
Can AppleScript check the type of path that is in the clipboard?

Also, does this workaround make sense?

  1. Create a temporary txt file
  2. Paste the path from the Bridge app.
  3. Reselect the path in the temporary file,
  4. Copy the path to the clipboard,
  5. Remove the temporary file,
  6. Run the apple script to create the folders

This will get the POSIX path of a single file (or the first, if more than one is selected in Bridge):

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

set pb to current application's NSPasteboard's generalPasteboard() -- get pasteboard
set urlString to pb's stringForType:"public.file-url"
set posixPath to (current application's NSURL's URLWithString:urlString)'s |path|() as text

To get a list of paths, you can use this:

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

set pb to current application's NSPasteboard's generalPasteboard() -- get pasteboard
set theData to pb's dataForType:(current application's NSFilenamesPboardType)
set thePaths to (current application's NSPropertyListSerialization's propertyListWithData:theData options:0 format:(missing value) |error|:(missing value)) as list

Thank you for providing the code. I run a test and found a difference between the Bridge clipboard and the FInder clipboard.

The path copied into the clipboard in plain text:
/Users/Shared/WEB

The path copied into the clipboard using the FInder and run through the Applescript:
{{«class utf8», 17}, {«class ut16», 36}, {string, 17}, {Unicode text, 34}}

The path copied into the clipboard using the Bridge app and run through Applescript:
{{«class utf8», 18}, {«class ut16», 38}, {string, 18}, {Unicode text, 36}}

The format looks consistent, the digits change in the clipboard depending on the method used to copy the path. What does the difference in numbers mean?

According to this online tool https://www.soscisurvey.de/tools/view-chars.php that detects hidden characters in copy and pate operations:

The path copied from the Finder has 17 characters, 17 bytes

The path copied using the Bridge app has 19 characters, 19 bytes

Any ideas to manage the extra characters?

I am trying with two different functions in the Bridge app to copy to the clipboard.
Not sure which function is technically correct.

I am still lost in understanding why I am unable to execute the folder-setup.scpt when the clipboard path input is done with the Bridge app. On the other hand, when the folder path is done with the Finder the script executes correctly.

function pathToClipboard(){
var sels = app.document.selections;
app.system(“echo “+decodeURI(sels[0].spec.fsName) +”|clip”);
}

function copyPath(){
var thumbs = app.document.selections;
app.system('echo '+ thumbs[0].spec.fsName + ‘|pbcopy’);
return;
}

Was it really difficult to provide the strings (paths) that screenshots show instead of broken links to screenshots. Okay, I’ll provide them for you:

Finder.app: “/Users/Shared/WEB”
Bridge.app: “/Users/Shared/WEB\r\n”

So, your workaround should be like this:


set posixPath to text 1 thru - 3 of (the clipboard as string)
set hfsPath to posixPath as POSIX file as text

tell application "Finder"
   make new folder at folder hfsPath with properties {name:"myNewFolder"}
end tell

NOTE: Instead of using highly specialized third-party utilities, I recommend using the Script Debugger. It shows in the area of variables visible and invisible text characters. It should show the path from Bridge.app exactly as I provided it above. After executing set posixPath to the clipboard as string

Your workflow removed the obscure characters introduce by the Bridge app fixing the issue.
Now the Bridge copy to clipboard function works with the folder-setup script in the same way it does with the OSX Finder. That is awesome!

I try to include the screenshots to show the string paths with the hidden characters and without the hidden characters. I should have included a text version as a backup. Another lesson learned.

Many thanks for your help!