@shruru, actually the return is not a "mess", but a well-organized set of data about the selection. By changing just two lines of the JXA script, it now returns ONLY a text list of the full path of each item selected in PathFinder.
However, you also need to change your "For Each" Action to use "Lines in Variable Collection".
Revised JXA Script
var ptyScriptName = "Get Items in PathFinder Selection"
var ptyScriptVer = "2.0" // Simplify to return only item paths
var ptyScriptDate = "2018-04-25"
var ptyScriptAuthor = "ComplexPoint" //JMTX mods
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PURPOSE:
• Get Items in PathFinder Selection
RETURNS: Text List of POSIX Path of Items in PathFinder Selection
REQUIRED:
1. macOS 10.11.6+
2. Mac Applications
• Keyboard Maestro 8.2+
• Path Finder 7.6.2+
TAGS:
REF: The following were used in some way in the writing of this script.
1. 2016-02-03, ComplexPoint, Keyboard Maestro Discourse
Finder and PathFinder selection paths from JavaScript for Automation
https://forum.keyboardmaestro.com/t/finder-and-pathfinder-selection-paths-from-javascript-for-automation/2871?u=jmichaeltx
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
// JAVASCRIPT Version for CocoaTech PATH FINDER
// for each selected item returns a triple of:
// - full path -- //JMTX simplified to return only this
//--- NOT RETURNED ---
// - folder path
// - file name (or "" if the selection is a folder)
function run() {
var pfSeln = Application("Path Finder").selection();
//return pfSeln ? pfSeln.map(pathFolderFile) : [];
var selectionList = pfSeln ? pfSeln.map(pathFolderFile) : []; //JMTX Add
return selectionList.join("\n"); //JMTX ADD
}
function pathFolderFile(x) {
var strPath = x.posixPath(),
lstParts = strPath.split(/\//),
blnFolder = x.kind() === 'Folder',
strFile = blnFolder ? '' : lstParts.pop();
//return [strPath + (blnFolder ? '/' : ''), lstParts.join('/') + '/', strFile];
return strPath; //JMTX ADD
}
Example Output
~/Documents/TEST/Test_File_Tags.txt
~/Documents/TEST/test_send_file.txt
Here's the full macro, which you may need to adjust for your needs:
2018-05-05 13:10 GMT-0500
- Fixed bug in last Action to use variable token
MACRO: Move List of Items Selected in PathFinder
#### DOWNLOAD:
<a class="attachment" href="/uploads/default/original/3X/1/a/1af3769e5b76f4bda037dfd50ace319182cd74c1.kmmacros">Get Text List of Items Selected in PathFinder.kmmacros</a> (6.4 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**
---
![image|501x1161](upload://uwTL2phTAF9lwZZK1nIX7WnYHbg.jpg)
---
Questions?