2

I'm brand new to Applescript and also have some limited experience with Terminal. I made simple shell script today that I saved on my desktop. It's named "Test.sh" and just copies a file from one folder to another. When I run sh ~/Desktop/Test.shfrom within Terminal, everything runs just fine. However, when I type do shell script "/Volumes/volume_name/Users/username/Desktop/Test.sh" inside Xcode as an Applescript command, nothing happens. I am using Xcode 4.4.1 on Mac OS 10.7.4 (though I guess it's irrelevant). What am I missing?

3
  • 3
    Are you sure you shell script is executable (chmod +x Test.sh) ? Commented Sep 7, 2012 at 17:35
  • I used this command but it returned chmod: Test.sh: No such file or directory. I changed Test.sh to ~/Desktop/Test.sh, but now it only waits for another command, without doing anything. What am I supposed to see as a result? Commented Sep 7, 2012 at 18:30
  • 2
    OK - that just makes the script executable - now you should try running your AppleScript code again and see if it works. Commented Sep 7, 2012 at 18:53

3 Answers 3

2

Because the path of the startup disk doesn't begin with "/Volumes/"

Use this to get the correct path

set shScript to quoted form of POSIX path of ((path to desktop folder as string) & "Test.sh")
do shell script shScript
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, but it still does not seem to be working. What ways are there to create a .sh file. Maybe mine just isn't working.
1

Enter Terminal and type the following:

cd ~
cd Desktop
sh Test.sh

Comments

0

Let us consider that the applescript you want to run inside the shell script is to empty the trash. Follow these steps:

  1. Open Terminal
  2. type "touch sample.sh" and press return
  3. Type "chmod +x sample.sh" and press return
  4. Type "open -e sample.sh" and press return, this open text editor
  5. Paste the below code in text file and save it.

!/bin/bash

osascript -e 'tell application "Finder" empty trash end tell'

  1. Go back to terminal. Type "./sample.sh". this will result in empty trash.

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.