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/")
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:
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.
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.
Replace
set currentFolder to do shell script "pwd"
with
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.
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.
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.