Page 1 of 1

Tag folder based on its contents directly

PostPosted: Mon Feb 25, 2019 8:55 am
by kristofk
In my folder structure, in the Documents folder, I have Xcode projects. An Xcode project is a folder with a bunch of files in it including a .xcodeproj file.

These projects can be at any depth anywhere in the folder structure. So in order to check if a folder is a project I have to check if it contains an Xcode Project file. If the folder is a project then I want to add the "Code" tag to it.

I tried the following rules but the problem is that this marks the topmost folder as "code".
https://ibb.co/gZWsZmg
https://ibb.co/LgHnSdy

How can I mark a folder that directly contains an Xcode project file?

Re: Tag folder based on its contents directly

PostPosted: Mon Feb 25, 2019 9:16 am
by Mr_Noodle
Unfortunately, using the "any of its sub-files" target includes things further down in the hierarchy. One solution would be to match the xcodeproj file itself, but use the ability to re-target a file in AppleScript as described here: viewtopic.php?p=1545#p1545

Re: Tag folder based on its contents directly

PostPosted: Mon Feb 25, 2019 10:06 am
by kristofk
Mr_Noodle wrote:Unfortunately, using the "any of its sub-files" target includes things further down in the hierarchy. One solution would be to match the xcodeproj file itself, but use the ability to re-target a file in AppleScript as described here: viewtopic.php?p=1545#p1545


This works perfectly.

Code: Select all
tell application "Finder"
   set posix_parent_dir to POSIX path of (container of (item theFile) as text)
   
end tell
return {hazelSwitchFile:posix_parent_dir}