Running a terminal command in applescript

Hi, I am new to all of this, so excuse any major mistakes!

I am trying to write a script to convert some RAW images files that I have. My camera (a Pentax DL2) is not supported by OS X, but the Pentax DL is. Therefore, if you alter the references to DL2 to just DL, then OS X recognises the files, and it is all peachy! The terminal command to do this is:

vim -b -c “:%s/*ist DL2/*ist DL /g|:wq” /Users/appleuser/Pictures/Editing/PEFs/IMGP0960.PEF

What I want to do is incorporate this into a folder action, so when I copy the files to the PEFs folder, it automatically applies this change. I though the easiest way to do this would be to use one of the existing folder action scripts, and change it. So I have got a script that is used to duplicate an image to jpeg, and I want to replace the “tell application” bit (in bold below), with my script. I understand that i have to write the line something like this:

do shell script “vim -b -c ‘:%s/*ist DL2/*ist DL /g|:wq’ /Users/appleuser/Pictures/Editing/PEFs/IMGP0962.PEF”

But I obviously dont want to refer to a specific image file (as above), but instead to the one being processed through the script. Does that make sense?? Do I have to define a “this_image” type statement, and put that in the do shell line???

Sorry again for being a complete novice…any help is much appreciated!

Model: Macbook pro
Browser: Safari 523.10.6
Operating System: Mac OS X (10.5)

I obviously can’t test this, but something like this:

set script_head to "vim -b -c ':%s/*ist DL2/*ist DL /g|:wq' /Users/appleuser/Pictures/Editing/PEFs/" -- name snipped off

on adding folder items to PEFs after receiving the_pix
	
	-- the_pix is a list of what was dropped on the PEFs folder
	-- set up the tests and locations you want to use, then
	
	repeat with aPic in the_pix
		tell application "Finder" to set N to name of aPic -- or have them in a list
		do shell script script_head & N -- concatenate the name back onto the script head.
	end repeat
	--
	
end adding folder items to

Thanks for the help, but I think that I have bitten off a bit too much for a newbie! I have tried the above script, and hunted around for other ways of getting it to work, and i cant figure it out. To ask a simpler question, is there a way of just applying that script to every “pef” item in a set folder?

Thanks again for the help!

set script_head to “vim -b -c ‘:%s/*ist DL2/*ist DL /g|:wq’ /Users/appleuser/Pictures/Editing/PEFs/”

OK…i think that I am making some progress…have a read and see what you think
The only problem, is I am having troubles with applying the vim shell script to all the files in the folder (i.e. its not working!)

Any help still much appreciated! Thanks


--Choose a folder and convert all DL2 PEF images to DL
set theFolder_1 to (choose folder with prompt "Convert DL2 images to DL in this folder:")


repeat with aPic in theFolder_1
	tell application "Finder" to set N to name of aPic
	do shell script "/usr/bin/vim -b -c ':%s/*ist DL2/*ist DL /g|:wq'" & quoted form of POSIX path of theFolder_1 & N
end repeat
--Put all converted PEF-files in a folder
tell application "Finder"
	set Tlist to list folder (theFolder_1 as alias) without invisibles
	set numFolders to ((number of folders in folder theFolder_1) + 1)
	set newTFolder to (make new folder of (theFolder_1 as alias) with properties {name:"Converted PEF-files " & numFolders}) as alias
	move (every file of (theFolder_1) whose name ends with ".pef") to folder newTFolder
end tell
display dialog "Files converted" buttons {"Okay"} default button "Okay" giving up after 8

Hi,

the path needs parentheses, otherwise only POSIX path of theFolder will be quoted, and a space character between the parameters

 do shell script "/usr/bin/vim -b -c ':%s/*ist DL2/*ist DL /g|:wq' " & quoted form of (POSIX path of theFolder_1 & N)

Thank you for your help…i have finally managed to sort it all out. The final script is below!
:smiley:


set theFolder_1 to (choose folder with prompt "Convert DL2 images to DL in this folder:")
tell application "Finder" to set theFiles to every file of folder theFolder_1 whose name extension is "pef"
set path_1 to quoted form of POSIX path of theFolder_1

repeat with j from 1 to the count of theFiles
	set thisFile to name of item j of theFiles
	do shell script "/usr/bin/vim -b -c ':%s/*ist DL2/*ist DL /g|:wq' " & (POSIX path of theFolder_1 & thisFile)
	
end repeat
display dialog "Files converted" buttons {"Okay"} default button "Okay" giving up after 8

Your script will fail, if there are any space characters in the paths of the files.
Here’s a shorter version


set theFolder_1 to (choose folder with prompt "Convert DL2 images to DL in this folder:")
tell application "Finder" to set theFiles to every file of folder theFolder_1 whose name extension is "pef"
repeat with oneFile in theFiles
	do shell script "/usr/bin/vim -b -c ':%s/*ist DL2/*ist DL /g|:wq' " & quoted form of POSIX path of (oneFile as alias)
end repeat
display dialog "Files converted" buttons {"Okay"} default button "Okay" giving up after 8

The last script I posted works 100% for me…thanks for your help :slight_smile:
Thanks for the shorter version though!

Might be, but I’d like to write scripts, which work in all cases.
Try your script choosing a folder with a space character in its name. :wink:

Ahhh…i see! Thanks :slight_smile: