I have an Automator service using a shell script that I'm executing using a keyboard shortcut to copy file/folder pathnames to the clipboard. The service receives selected files or folders in Finder app, passes them as arguments to the following shell script.
for f in ”$@”
do
echo \""$f"\"
# also tried it with "\"$f\""
done
This outputs to a copy to clipboard
action. It works fine when just pasting into a text editor, Finder's search box, etc.
However, I also have a conditional script running through QuicKeys that allows me to paste text in certain problematic text fields of various windows in an audio app called REAPER (otherwise, the shortcut for pasting text, ⌘+v, simply doesn't work). The weird thing is, if I copy a pathname from Finder, paste it into a text editor, select it, and copy it, then the script to paste the copied text works fine in REAPER. But going straight from Finder, copying the pathname to the clipboard, then trying to paste it in a text field in REAPER doesn't work.
Here's the applescript I'm calling with the QuicKeys shortcut.
global frontApp, frontAppName, windowTitle, seltxt
set windowTitle to ""
tell application "System Events"
set frontApp to first application process whose frontmost is true
set frontAppName to name of frontApp
tell process frontAppName
tell (first window whose value of attribute "AXMain" is true)
set windowTitle to value of attribute "AXTitle"
end tell
end tell
end tell
on is_running(appName)
tell application "System Events" to (name of processes) contains appName
end is_running
set RprRunning to is_running("REAPER")
try
if RprRunning then
tell application "System Events"
if exists (window "Save" of process "REAPER") then
tell text field "Save As:" of window "Save" of application process "REAPER" to set seltxt to the value of its attribute "AXSelectedText"
tell text field "Save As:" of window "Save" of application process "REAPER" to set the value of its attribute "AXSelectedText" to the clipboard
else if exists text field 6 of window windowTitle of application process "REAPER" then
tell sixth text field of window windowTitle of application process "REAPER" to set seltxt to the value of its attribute "AXSelectedText"
tell sixth text field of window windowTitle of application process "REAPER" to set the value of its attribute "AXSelectedText" to the clipboard
else if exists (text field 2 of window windowTitle of application process "REAPER") then
tell second text field of window windowTitle of application process "REAPER" to set seltxt to the value of its attribute "AXSelectedText"
tell second text field of window windowTitle of application process "REAPER" to set the value of its attribute "AXSelectedText" to the clipboard
else if exists (text field 1 of window windowTitle of application process "REAPER") then
tell first text field of window windowTitle of application process "REAPER" to set seltxt to the value of its attribute "AXSelectedText"
tell first text field of window windowTitle of application process "REAPER" to set the value of its attribute "AXSelectedText" to the clipboard
end if
end tell
return seltxt
end if
end try
I'd really love to get this working properly. I've been racking my brain trying to figure out why copied file/folder pathnames need to be pasted & copied in some text field outside of REAPER before they can be pasted into a text field in REAPER.
Well, I'm not sure if there might be something to fix still with one of the scripts. But for now, I seem to have stumbled upon a solution.
Rather than piping the output from the shell script directly to the
copy to clipboard
action, I added afilter paragraphs
action before it, and set it toreturn paragraphs that: begin with: "
This seems to have had the same effect as pasting and copying the path name string in a text field outside of REAPER, and I'm now able to paste the pathnames directly into text fields in reaper after copying them from selected files/folders in Finder.