Problem with Macro


I want to create two folders inside the current folder, Deliverables and Resources, and inside resources I want to copy some files to it. I want the Macro to be triggered after I press a hotkey.

I'm trying to run the following Apple Script:

-- Get the current working directory
set currentFolder to do shell script "pwd"

-- Create the first folder
do shell script "mkdir -p " & quoted form of (currentFolder & "/Folder1")

-- Create the second folder
do shell script "mkdir -p " & quoted form of (currentFolder & "/Folder2")

-- Copy files to the first folder (adjust source path as needed)
do shell script "cp /Users/schweine/Downloads/Tools/* " & quoted form of (currentFolder & "/Folder1/")

This is the Macro:
CreateFolders.kmmacros (2.3 KB)

But the Macro doesn't fire up.

Any help will be appreciate it.


Hi and welcome to the forum! :wave:t3:

Please post your entire macro so we can see what's going on.

What is your goal here? Is this the entire macro or one function of it?

Here's what it does:

  1. Set the current working directory.
  2. Create a folder named "Folder1" in the current directory.
  3. Create another folder named "Folder2" in the same directory.
  4. Copy files from "/Users/schweine/Downloads/Tools/" to the "Folder1" directory.

I don't see any real problem with it. Is the macro enabled? Have you checked your group settings?

Yes, I've enabled the Macro group:

Were you able to run it?

I tried to run the debugger to no avail. It doesn't show me anything.

2023-10-31 15:42:59 Execute an AppleScript failed with script error: text-script:108:181: execution error: mkdir: //Folder1: Read-only file system (1). Macro “CreateFolder” cancelled (while executing Execute AppleScript).

The error message you're getting, mkdir: //Folder1: Read-only file system (1), suggests that the script is trying to create a folder at the root of your filesystem (because of the double slash //). This is likely because the pwd command isn't returning the expected current working directory or it's returning an empty string.

Here's a breakdown of potential problems and solutions:

  1. Wrong Working Directory: If the script is being run in an environment where the current working directory is not properly defined or inaccessible (e.g., certain applications or contexts), the pwd command might return an empty string, which would lead to this error.

    Solution: Ensure you're running the script in a context where the working directory is meaningful and accessible.

  2. Using AppleScript's "path to": AppleScript has its own way of getting paths. If you're running this script in a context where shell scripts might have issues, you might want to use AppleScript's built-in commands.


    set currentFolder to do shell script "pwd"


    set currentFolder to (path to me as string) -- This gets the path to the script itself

    Note that path to me would give the path to the script or app running the AppleScript, so adjust accordingly if that's not what you want.

  3. Permission Issues: There might be permission issues with the location you're trying to create the folder in.

    Solution: Ensure that you have the appropriate write permissions in the directory where you want to create the folders.

  4. Alternative to pwd: If you want to use the shell script way and ensure that you're always working with the user's home directory (for example), you can replace pwd with:

    set currentFolder to do shell script "echo ~"

This will set currentFolder to the user's home directory.

In any case, you should carefully test the modified script to ensure it behaves as expected, especially before copying or moving files to avoid data loss.


To get the current folder from finder this can be used:

tell application "Finder"
    set currentFolder to POSIX path of (target of front window as alias)
end tell

Thanks for your help @noisneil .


This is the final Macro, if someone else might need something similar:
mkDirsNCpFiles.kmmacros (2.7 KB)