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
Copy the folder path using the Adobe Bridge Application
Paste the path into a text file
Reselect the path
Copy to clipboard
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.
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?
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?
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;
}
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.