0

I'm trying to get the script to check if there is a variable folder name, eg. "folder x", present from within a folder that has folders a-z for example?

The rest of the script works fine but the problem is that no matter what I've done so far I only get "yes" as the result of this line if exists folder theTitleCV of alias "Comics:" then.

My script so far:

set theTitleCV to "Folder X"
set theTitle to "Folder X-52"

--Creating the folder if it doesn't exists
tell application "Finder"
    if exists folder theTitleCV of alias "Comics:" then
        if theTitleCV is equal to theTitle then
            make new folder of alias "Comics:" with properties {name:theTitleCV}
        else
            set theTitleResult to ((display dialog "Title Options" buttons {theTitleCV, theTitle, "Cancel"} default button 2))
            set theButton to button returned of theTitleResult
            make new folder of alias "Comics:" with properties {name:theButton}
        end if
    else
        return "Yes"
    end if
end tell

Thanks in advance for any help that is offered.

P.S. If this type of question has been asked and answered before, please just point me in the direction as to what to search for. Thanks :)

5
  • What is Comics? It should work if Comics is a volume and if so disk "Comics" is preferable over alias "Comics:" Commented Apr 24, 2020 at 10:57
  • Yes, Comics is a volume. Ok, thanks. I'll try that and get back to you Commented Apr 24, 2020 at 23:13
  • Ok, just tried that, and tried it on another volume as well, and nothing has changed. It's still resulting in Yes even though there is, definitely, no folder called Folder X Commented Apr 24, 2020 at 23:23
  • Please read your script: The Yes branch is if exists folder, you need if not exists folder Commented Apr 25, 2020 at 4:30
  • thank you vadian for pointing out the obvious, which I clearly missed, as I was looking at/working on it for too long :) Commented Apr 25, 2020 at 9:22

1 Answer 1

0

thanks to everyone who helped and especially to vadian for spotting the obvious mistake.

I have now fixed the script and have added a display dialog to go with it.

set theTitleCV to "Folder X"
set theTitle to "Folder X-52"


--Creating the folder if it doesn't exist
tell application "Finder"
    if not (exists folder theTitleCV of disk "Comics") then
        if theTitleCV is equal to theTitle then
            make new folder of disk "Comics" with properties {name:theTitleCV}
        else
            set theTitleResult to ((display dialog "Title Options" buttons {theTitleCV, theTitle} default button 2 with icon ":System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:GenericFolderIcon.icns" as alias))
            set theButton to button returned of theTitleResult
            make new folder of disk "Comics" with properties {name:theButton}
        end if
    else
        tell application "Finder" to activate
        return display dialog "" & return & "Thank you for checking," & return & "but this folder already exists." with title "Folder Already Exists" buttons {"OK"} default button 1 with icon ":System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:AlertNoteIcon.icns" as alias
    end if
end tell
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.