I have a folder called '0 current report'. Within that folder is another folder called 'jobname 1234' where jobname could be any word(s) and 1234 could be any 0-9 digits.
Within 'jobname 1234' will be a word document called '1234 jobname R01'.
Hi Chris yes I thought there must be an easier way.
Root folder will always be 0 current report.
There will always be only one folder inside 0 current report called ‘jobname 1234’ (where jobname will be one or more words and 1234 will be any 4 digit number).
There will be a variable number of files and folders inside ‘jobname 1234’ including several word documents. But only one word document will have the name form of ‘1234 jobname R01’ (where jobname will be one or more words and 1234 will be any 4 digit number).
If I'm correct then this task is fairly simple, and I'll start with AppleScript.
Adjust the sourceFolderPath for your system, and run this from Apple's Script Editor.app or better yet Script Debugger if you have it.
--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/12/30 21:34
# dMod: 2021/12/30 21:34
# Appl: Finder, System Events, Microsoft Word
# Task: Open a Word Document Buried in a Folder Hierarchy.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @Finder, @System_Events
--------------------------------------------------------
use AppleScript version "2.4" --» Yosemite or later
use framework "Foundation"
use scripting additions
--------------------------------------------------------
## USER SETTING ##
set sourceFolderPath to "~/Library/Mobile Documents/com~apple~CloudDocs/untitled folder/xx/0 current report/"
--------------------------------------------------------
set sourceFolderPath to ((current application's NSString's stringWithString:sourceFolderPath)'s stringByExpandingTildeInPath) as text
set sourceFolderAlias to alias POSIX file sourceFolderPath
set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {""}}
tell application "Finder"
set folderList to folders of sourceFolderAlias as alias list
set jobFolderAlias to item 1 of folderList
set jobFolderName to name of jobFolderAlias
end tell
set jobNumber to first word of jobFolderName
set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, " "}
set jobName to rest of words of jobFolderName as text
set AppleScript's text item delimiters to oldTIDS
set jobName to jobName & space & jobNumber
tell application "System Events"
set fileList to files of jobFolderAlias whose name contains jobName
if length of fileList = 1 then
open item 1 of fileList
else
error
end if
end tell
set AppleScript's text item delimiters to oldTIDS
--------------------------------------------------------
This task should be fairly simple to do with the shell and with Keyboard Maestro native actions as well, but I'll hold off until I know the answer to the root question.
Attached is screenshot of the error. There is also an error if I try to run it from Script Editor.app.
To get the path name, I ⌥ clicked on the folder '0 current report' then pressed 'copy as pathname'. I then pasted this path into the script so it reflected my system.