Folder List Macro

Folder List Macro

There are two approaches to do the same thing in this macro, the second of which is disabled.

The second, which is all AppleScript, works fine.

But I can't get the first (which is two actions) to work the same way. The AppleScript reads the list of selected folders as a string of characters.

So the Choose a Folder action is returning its list differently but I don't know how. It seems to list each folder on a line of its own. But AppleScript doesn't seem to like that.

Any clue how to rewrite the AppleScript in the two-action version to match the one-action version? TIA

Folder List.kmmacros (3.9 KB)

This seems to do the job:

set kmInst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
    set theSelection to getvariable "localFolders" instance kmInst
end tell

-- Split the single string into a list using linefeed as the delimiter
set folderList to paragraphs of theSelection

-- Loop through each folder in the list
repeat with aFolder in folderList
    if length of aFolder > 0 then -- check if the line is not blank
        display dialog aFolder
    end if
end repeat

Thanks, @noisnieil. That does indeed solve my problem.

Especially appreciate the if statement to catch empty paragraphs. When I select a single folder, there isn't one but if I select multiple folders there is. That would have driven me nuts!

Thanks, again!

1 Like