What I’ve achieved so far is “copy the file name without the extension” (which I did in my macro presented on the screenshot).
Next step would be to create a macro which paste that name on a selected file. I could record all the keystrokes ‘Return’ -> ’ CMD + V’ -> ‘Return’, however they are not seem to be robust at all (sometimes a macro will change a selection for some reason to a file above or below of my initial selection!), that’s why I prefer to use Applescript: it’s faster and consistent.
You mean a file different from the file you got the name from?
###Save name of selected item in Path Finder to Keyboard Maestro variable.
Since you need to use AppleScript for this step it is more efficient to do all of it within the script. This is easily done, since we can get both the name and name extension of the selected item from Path Finder.
---------------------------------------------------------------------
# Get Name of Selected Item in Path Finder without name extension.
---------------------------------------------------------------------
tell application "Path Finder"
set pfSelection to the selection
if length of pfSelection = 1 then
set theItem to item 1 of pfSelection
set itemName to name of theItem
set fileExtension to name extension of theItem
if fileExtension ≠ "" then
set AppleScript's text item delimiters to "." & fileExtension
set itemName to (text items 1 thru -2 of itemName)
set AppleScript's text item delimiters to ""
set itemName to itemName as Unicode text
end if
else
beep
end if
end tell
tell application "Keyboard Maestro Engine"
set kmVariableName to "pfSavedName"
try
set value of variable kmVariableName to itemName
on error
make new variable with properties {name:kmVariableName, value:itemName}
end try
end tell
---------------------------------------------------------------------
###Rename the selected item in Path Finder.
Because scripting in Path Finder is broken in places this is harder than it should be
It's necessary to use the Finder to do the rename, but it works alright and updates quickly in PF.
---------------------------------------------------------------------
# Rename Selected Item in Path Finder.
------------------------------------------------------------
tell application "Keyboard Maestro Engine"
set kmVariableName to "pfSavedName"
if length of (get variables whose name is kmVariableName) = 1 then
set pfSavedName to value of variable kmVariableName
else
error "Variable '" & kmVariableName & "' does not exist!"
end if
end tell
tell application "Path Finder"
set pfSelection to the selection
if length of pfSelection = 1 then
set theItem to item 1 of pfSelection
set theItem to POSIX path of theItem
else
beep
end if
end tell
set theItem to alias POSIX file theItem
tell application "Finder"
set name of theItem to pfSavedName
update parent of theItem
end tell
---------------------------------------------------------------------
* Note: I've file a bug report with Cocoatech about renaming items being broken, but it will be more effective if others do the same.
Wow that some amount of code! I can’t make this work for me unfortunately (I mean nothing is happening), my guess is I am doing something wrong here
I’ll try to explain it again:
I have a workable macro (CTRL + C) that copies the filename (once I manually select the file) without the extension, as a plain text to the System Clipboard. This works perfect for me.
Now, I am trying to create another Macro (let’s string it to CTRL + V) which paste that plain text onto a selected file (located in a different folder) instantly. What I mean by that is ‘if I would do it manually which involves more actions and takes more time: select the file - > Return Key -> Paste (Plain text from the clipboard) -> Return Key’.
Assuming you will select the file manually to rename, then the process is fairly easily done as shown in the (Working with the Finder Selection topic.
I could be as simple as:
Rename File %Variable%Path% to %CurrentClipboard%
If you want to keep the extension, then you will need to do a bit more work, using the Get File Attribute action to get the current extension and include it in the rename.
Just curious...(I realize, I'm jumping in 4 years after the fact and so, only if this still is of interest), Peter 'S' : Where are the two files, the first one with a name you would like to copy and the second, onto which you would like to paste the name of the first.
For example, are both files sitting in separate folders on your desktop, or are they in your home folder or (?). This is important data that will guide you to an accurate resolution.