1

I‘m again trying to make a siri-shortcut which let you run applications on your Mac.

https://www.icloud.com/shortcuts/f74c9bd89f1a4e71a3e8f72da5cf5ab7

It's making a list of all your applications in a text document, but there is the text document self also in the list. Can I delete the name of the document in this list with a command and without using keyboard?

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

  • I like what you were thinking with the screenshots, but (with the exception of the one that shows the commands you're running over SSH) I don't think they're helping to support your real question which is, fundamentally, "how do I list a directory, redirect that list into a file, but prevent the list file itself from showing up in the listing?" – TheDudeAbides Sep 14 at 20:13
4

ls > Applications.txt is going to list the Applications.txt file in the list.

Though I don't entirely understand all of your workflow, adding the -d flag should do the trick, by specifying *.app.

ls -d *.app > Applications.txt

Just like your previous approach though, that won't catch .app files buried in subdirectories (like your Adobe Suite). You can modify find's maxdepth parameter for something like that:

find . -maxdepth 1 -type d -name "*.app" > Applications.txt

If you wish to search within all subdirectories of the current one, simply omit the -maxdepth option altogether.

If you have a problem with the pathname being part of the output (e.g., you want Terminal.app not ./Utilities/Terminal.app), then try this instead:

cd /Applications
find * -type d -name "*.app" -exec basename "{}" \; > Applications.txt

If you want to find any application anywhere on your Mac, try:

mdfind -interpret "kind:application"  # this is localized for your language

The mdfind command uses Spotlight's index, so it's fast, but (being an index) it may not always represent the exact, up-to-the-minute state of the filesystem. How to remove the pathname from the front is left as an exercise for the reader (hint: xargs -I{} basename "{}").

  • There are just the .app files in the text document. Is there also a command which list all .app files like Adobe Photoshop CC 2019.app? – JonathanXD12 Sep 14 at 9:07
  • @JonathanXD12 See dxdc's updated answer. The find command, or the mdfind command (which uses the Mac's Spotlight index) are probably better tools for the job than ls. – TheDudeAbides Sep 14 at 20:08
  • Increasing the maxdepth might be good enough- ` find . -maxdepth 3 -type d -name '*.app' -exec basename {} \; > FILE` – fd0 Sep 15 at 16:53
1

It might be easier to avoid the problem altogether by creating the text file outside the Applications folder. This will also make sure that the workflow works for users without write access there. In the SSH action use

cd /Applications
ls > ~/Library/Mobile\ Documents/iCloud~is~workflow~my~workflows/Documents/Applications/Applications.txt

to create the file directly at the place you want it to end up.

  • Thank you! It's working! – JonathanXD12 Sep 14 at 17:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .