Visit Our UNIX and Linux User Community


Terminal vs. Applescript


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Terminal vs. Applescript
# 1  
Old 09-24-2009
Java Terminal vs. Applescript

I am running Mac OS X (10.5). I run the following script successfully in terminal in order to split an mp3 file into 3 smaller mp3 files...

split -b 8667k -a1 Monday.mp3 Levin-Hour_; ls Lev* | sed "s/.*/mv '&' '&.mp3'/g" | zsh

However, when I run a similar script within the Applescript editor using the 'do shell script' command, the files split yet none of the 3 newly created files include the 'mp3' extension (they are in mp3 format however). Although I realize that I can simply rename the files within Applescript, the purist in me wants to know how to fix this. Here's what my Applescript command looks like...

do shell script "split -b 8667k -a1 Monday.mp3 Levin-Hour_; ls Lev* | sed " & "s/.*/mv '&' '&.mp3'/g" & "| zsh"

By the way, I know that I can easily split the file via a GUI editor. However, I am trying to run an automated script that downloads several files in a scheduled fashion. Therefore, I want to correct this via scripting if at all possible.

Any insight would be greatly appreciated. This may be more of an Applescript problem, but I thought I would at least throw it out there - thanks!!
# 2  
Old 09-24-2009
I don't have much experience with applescript but it looks like you might need to escape the single quotes and possibly the pipe. Why are there ampersands in the middle of the command? Does it need to be split up that way?
# 3  
Old 09-25-2009
Your points are valid. To be honest, the problem came about late last night and my brain was fried. I tried several combinations until it finally compiled as you see it. The program ran and compiled, but clearly something is not allowing it to complete with total success (e.g., no 'mp3' extensions). When I get home tonight, I'll play around some more with the ampersands, pipes, and single quotes until I can hopefully meet with success. Thanks for your suggestions !! Smilie

---------- Post updated 09-25-09 at 10:06 AM ---------- Previous update was 09-24-09 at 03:14 PM ----------

It's amazing how a good night's sleep can help one solve a problem. For those who ever want to do something similar using Applescript, I got it to work with these two lines...

set TheScript to "s/.*/mv '&' '&.mp3'/g"

do shell script "split -b 8667k -a1 Monday.mp3 Levin-Hour_; ls Lev* | sed " & quoted form of TheScript & "| zsh"

Bottom line - since the actual shell command included a statement with double quotes, I had to use Apple's quoted form statement to insure that the compiler read the double quotes as part of the script instead of just normal double quotes that would surround a string.

Previous Thread | Next Thread
Test Your Knowledge in Computers #384
Difficulty: Medium
The Unix df command reports damaged disk space on file systems.
True or False?

10 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

Delete or move post to applescript area

i posted an applescript question in the wrong area, trying frantically to delete or move before I get in trouble for posting question in wrong area. it is the one about opening webpages and searching text with applescript, thanks (1 Reply)
Discussion started by: ilovedoritos
1 Replies

2. OS X (Apple)

Applescript application call problem...

Hi all... I am trying to create a shell project purely for this Macbook Pro. I do NOT want to use SOX as the sampling _source_ but Quicktime instead, the idea being that NO third party installs will be needed. The code below works fine except the commented out Applescript line does not do... (2 Replies)
Discussion started by: wisecracker
2 Replies

3. Shell Programming and Scripting

SED command works in terminal, but not Applescript

The following command works perfectly in Terminal, but not in Applescript. (Returns "unknown token" error for square brackets.) (new to site. sorry.) I have an Applescript that is designed to find and remove any square-bracketed text, including the square brackets. I ran the following code from... (1 Reply)
Discussion started by: Phillip Acosta
1 Replies

4. Shell Programming and Scripting

applescript & grep - sed command

I'm new using Unix commands in applescript. The following script you choose different folders with PDfs, get file count of PDfs on chosen folders, & write the results in text file. set target_folder to choose folder with prompt "Choose target folders containing only PDFs to count files" with... (0 Replies)
Discussion started by: nellbern
0 Replies

5. OS X (Apple)

[Solved] Running shell code in AppleScript without Terminal

What I want my script to do is to run a command in Terminal and close that same Terminal window when the process is complete. Of course I could ad a delay of 6 seconds to complete the process, but it may not be enough every time. To simplify my question, this is what I want to achieve.... (9 Replies)
Discussion started by: ShadowofLight
9 Replies

6. Shell Programming and Scripting

Scripting in AppleScript

What I want my script to do is to run a command in Terminal and close that same Terminal window when the process is complete. Of course I could ad a delay of 6 seconds to complete the process, but it may not be enough every time. To simplify my question, this is what I want to achieve.... (0 Replies)
Discussion started by: ShadowofLight
0 Replies

7. OS X (Apple)

Need help writing an Applescript to launch a specific Terminal Command...

I developed a script in Lingon (which is an automated script editor developed for OS X) that is used to automatically restart programs only if they crash. The script itself does just that, but I only want it to load if I'm going to use the specific application that it's designed to protect. In the... (2 Replies)
Discussion started by: JFraser1
2 Replies

8. Shell Programming and Scripting

Need help writing an Applescript to launch a specific Terminal Command...

I developed a script in Lingon (which is an automated script editor developed for OS X) that is used to automatically restart programs only if they crash. The script itself does just that, but I only want it to load if I'm going to use the specific application that it's designed to protect. In... (3 Replies)
Discussion started by: JFraser1
3 Replies

9. OS X (Apple)

AppleScript to Bash

Any ideas on converting an applescript into bash? Simple method to get rid of delimiters? (9 Replies)
Discussion started by: unimachead
9 Replies

10. UNIX for Dummies Questions & Answers

BASH or applescript keygen

Please help me to make this script to create a key based on these parameters: the output of $USER is smithm for mike smith the output of id smithm is uid=1042(smithm) gid=20(staff) groups=20(staff), 1025(group1), 1057(group2), 1028(group5), 1038(group3), 1037(group4) I need a script that... (0 Replies)
Discussion started by: glev2005
0 Replies

Featured Tech Videos