Applescript to make new folder

后端 未结 5 950
死守一世寂寞
死守一世寂寞 2021-01-16 03:10

I Want to make a new Folder command in apple script

Why dosent this script work?

tell application \"Finder\"
activate
end tell
tell application \"Sys         


        
相关标签:
5条回答
  • 2021-01-16 03:30

    NOTE: This can fail for two reasons;
    (1) '~' trapped in singlequote won't parse.
    (2) space in '/New Folder/' will break the path.

    do shell script "mkdir -p '~/Desktop/New Folder/Bleep/Bloop'"
    

    SOLVED:

    do shell script "mkdir -p ~/Desktop/" & quoted form of "New Folder/Bleep/Bloop" 
    
    0 讨论(0)
  • 2021-01-16 03:33

    You can do it more directly with AppleScript:

    tell application "Finder"
        set p to path to desktop -- Or whatever path you want
        make new folder at p with properties {name:"New Folder"}
    end tell
    
    0 讨论(0)
  • 2021-01-16 03:40
    tell application "Finder"
    activate
    end tell
    tell application "System Events"
    tell process "Finder"
        tell menu bar 1
            tell menu bar item "File"
                tell menu "File"
                    click menu item "new folder"
                end tell
            end tell
        end tell
    end tell
    end tell
    
    --you capitalize the N in new folder the new folder button is not capped.
    
    0 讨论(0)
  • 2021-01-16 03:48

    You can directly with an applescript script by simulating keystroke on ("N" and command and shift) this will create a new folder on the desktop or in the open Finder window.

    Below the script, you can test it in the script editor

    tell application "System Events" to tell process "Finder"
        set frontmost to true
        keystroke "N" using {command down, shift down}
    end tell
    

    Your script works if you add under "tell process" Finder " "set frontmost to true" Which give

    tell application "System Events"
        tell process "Finder"
            set frontmost to true
                    tell menu bar 1
                tell menu bar item "File"
                    tell menu "File"
                        click menu item "New folder"
                    end tell
                end tell
            end tell
        end tell
    end tell
    
    0 讨论(0)
  • 2021-01-16 03:53

    I don't know if running bash commands within AppleScript is cheating, but you can also do:

    do shell script "mkdir '~/Desktop/New Folder'"  
    

    Which is useful when you need to create sub folders on-the-fly when they don't exist yet:

    do shell script "mkdir -p '~/Desktop/New Folder/Bleep/Bloop'"  
    
    0 讨论(0)
提交回复
热议问题