Finding first file in folder and opening with specific application

I am so sorry to ask this - being new to the community, but I've been struggling with this problem for 5 days now and still no working solution. I think it's time to ask for help.

I'm trying to navigate into a folder I have listed as "Articles". From there I'd like to select the first file (they're all in .pdf format) that appears within that folder (I know there are different ways to sort it - but really the order in which they're opened makes no difference) and open it with an application called "GhostReader Plus".
That's it.

Can anyone help me with this? It's probably a real simple solution, but being a total newb, I'm hitting a wall.

Hi. Welcome!
1st: open the first PDF file in a folder.
2nd: the order of the files doesn't matter.
Does this mean you want to open a random PDF file in a folder?

Hi Yu_Cai, thanks for asking... Ya sure, opening in a random order is fine. I just need to get them opened... That simple.

@uvb76static - This is quick and rough but it's simplistic.

Try this below.

Create a trigger, change my added folder, "kc/Desktop Articles", to your Articles folder location and then replace Preview, with GhostReader Plus, in the Open Finder Selection Action.

See if it gets you where you need to be.

KC

For getting more:
You can use "For each path in folder" macro to do things onto files in this folder one by one.
You can use "Split path" macro to extract the file extension of a file.
You can use "If then" macro to check if the file extension is PDF.

We also can define a variable called findAPDFFile at the beginning, set it to False. If we really find a PDF file:
We use "Open a file" macro to open it. Set findAPDFFile to True. If we don't find a pdf file:
We use "Display text" macro to report error:"no PDF files found in this folder."

You can test this macro on your machine:
ANSWER Finding first file in folder and opening with specific application v0_Backup_20200330_0931_v0.kmmacros (9.8 KB)

Do something like this:

  • For Each action with Path variable with Folder Contents collection ~/Documents/Articles
    • Open a File action %Variable%Path% with application “GhostReader Plus”
    • Cancel This Macro

That will open the first file in the folder and then stop.

1 Like

Oh snap!!!! I shoulda just posted the question right from the start. I tried all of the responses you guys posted and every one of them worked perfectly for me. There's no way I would have gotten any of them on my own. Simply not comfortable enough with KM yet. Thank you all sooooo very much.

1 Like