Execute a shell command?

[quote=105109:@Richard Summers]I am actually starting to get so angry over this ridiculous problem that I am starting to feel really ill.
I am way out of my depth here, and know when to quit.[/quote]

Richard,

I know you are ambitious and seldom give up before you understand fully what you set yourself to achieve. But sometimes, a break is beneficial. Does not mean you have to give up forever with using sips. Just that for today, it does not work. If Xojo resize works, maybe that is sufficient for what you wanted to do originally ?

Better is not always better :wink:

Michel - I totally understand, and agree with you.

I am annoyed because even if I took a week off, I still wouldn’t understand it when I came back.
Due to my lack of understanding - I am now stuck with a method of achieving the end result which is less than satisfactory.

It seems pointless to save a resized image which will look C R A P, therefore I have to forget the idea completely.
I will never settle for second best - if I can’t do something properly, I would rather not do it.

I do understand what you are saying though, and appreciate you trying to help :slight_smile:

I will move on to learning something new, which hopefully makes more sense to me.
Thanks :slight_smile:

What the shell does is to execute the same code as what could be typed into the Terminal utility.

So to understand better how a shell command works, I usually test it first with Terminal, before doing a shell with it.

That is exactly what I did. Follow exactly and you will be able to generate a sized down version of the picture.

  • Get from Examples Projects/Graphics and multimedia/DragPicture the picture Studebaker.jpg and copy it to your desktop
  • Launch Terminal from the Applications/Utilities folder
  • Type cd /Users/<yourusername>/Desktop and enter. Your user name appears when you look in Macintosh HD, in the folder called Users.
  • Your prompt will end as Desktop $
  • copy and paste this into the Terminal window :

sips -s format png -Z 100 Studebaker.jpg --out stud_100.png

Then press Enter. You do not need the path to sips, as OS X knows where to find it.

Now I tested this and if you follow exactly the instructions, stud_100.png should appear on your desktop.

To adapt this to your shell, change Studebaker.jpg to whatever the shellpath is to your source file, and stud_100.png to whatever the output file shellpath is. The 100 stands for the size of the picture.

Hope this helps.

Thanks Michel,
I appreciate you taking the time to go through those steps for me!
I did as you advised and it worked perfectly.

I am now trying to follow your advice regarding getting this to work in my project.
The trouble I have is I do not know the path to the source image, as the source image is the image which gets dropped onto canvas 1.

Here is the code so far in the Canvas1 DropObject event:

[code]// DEFINE VARIABLES
dim pic, newpic as picture

// CHECK IF AN IMAGE WAS DROPPED ONTO THE CANVAS
if obj.FolderItemAvailable then

// ATTACH THE DROPPED IMAGE TO THE PICTURE OBJECT CALLED PIC
pic = picture.open(obj.FolderItem)

// RESIZE TO 512 X 512 AND SAVE
// CREATE A NEW 512 X 512 PICTURE OBJECT CALLED NEWPIC
newpic = new picture(512,512,32)

// DRAW PIC AT THE NEW SIZE INTO THE PICTURE OBJECT CALLED NEWPIC
newpic.graphics.drawpicture(pic, 0,0,512,512, 0,0,pic.width,pic.height)

// RESIZE AND SAVE THE IMAGE
Dim s As New Shell
s.mode = 0
s.Execute (sips -s format png -Z 512 UNKNOWNPATH --out 512.png)[/code]

The only problem I seem to have now is how to find the full shellpath to the source image???

s.Execute("sips -s format png -Z 512 "+obj.FolderItem.shellpath+" --out 512.png")

Michel - with all due respect - the line of code you kindly provided above, means absolutely nothing to me :frowning:

I understand that obj.FolderItem refers to the dropped image, but I still have no idea how to find out it’s full shellpath???
This is the very same problem that I have had since the very start.

How on earth do I get the full path to something dropped onto a canvas by the user?

Sorry if I sound dumb, but I have absolutely no idea how to obtain it’s path.

[quote=105181:@Richard Summers]Michel - with all due respect - the line of code you kindly provided above, means absolutely nothing to me :frowning:

I understand that obj.FolderItem refers to the dropped image, but I still have no idea how to find out it’s full shellpath???
This is the very same problem that I have had since the very start.

How on earth do I get the full path to something dropped onto a canvas by the user?

Sorry if I sound dumb, but I have absolutely no idea how to obtain it’s path.[/quote]

Richard, no question has to sound dumb. You really need to get familiar with the FolderItem concept. If you find some time, try to read the LR http://documentation.xojo.com/index.php/FolderItem

If you read carefully the code :

s.Execute("sips -s format png -Z 512 "+obj.FolderItem.shellpath+" --out 512.png")

obj.FolderItem is the FolderItem corresponding to the picture dropped into your app. obj.FolderItem.shellpath is the ShellPath in the FolderItem. ShellPath is the location, the path written the way you would in /Users/Richard/Pictures/mypicture.jpg for instance. Path can also be written in the form of a URL (URLPath) and other forms.

That’s how on Earth (and probably on Mars as well) we get the path to the file pointed to by the FolderItem. That’s all there is to it :slight_smile:

Arggggghhh,
This is now bordering on absurd!

I put this code in my app and then dragged an image onto the canvas:

//dim f2 as New folderitem f2=obj.FolderItem MsgBox f2.ShellPath

This popped up a MsgBox and gave me the shell path:

I cannot replace “+obj.FolderItem.shellpath+” with the path in the screenshot above, as that refers to my computer, and I have no idea where the user’s image will be coming from???

This still makes absolutely no sense to me?
How can I put in the shell path, when I don’t know what the shell path will be???

I then tried this - to no avail?

Dim s As New Shell s.mode = 0 s.Execute("sips -s format png -Z 512 f2.shellpath --out 512.png")

You still making the mistake I pointed out this morning (or your afternoon perhaps)

NOT THIS

s.Execute("sips -s format png -Z 512 f2.shellpath --out 512.png")

but this

s.Execute("sips -s format png -Z 512 "+f2.shellpath+" --out 512.png")

note the double quotes and plus signs on either side of “f2.shellpath”

Dave,
this also does nothing at all??

[code]dim f2 as New folderitem
f2=obj.FolderItem

Dim s As New Shell
s.mode = 0
s.Execute(“sips -s format png -Z 512 “+f2.shellpath+” --out 512.png”)[/code]

dim f2 as New folderitem
f2=obj.FolderItem
    
Dim s As New Shell
s.mode = 0
s.Execute("sips -s format png -Z 512 "+f2.shellpath+" --out 512.png")
msgbox "F2 is "+f2.shellpath+"    RESULT="+sh.result

post back what the msgbox says

This is my entire code in the canvas1 DropObject event:

[code] // INITIALIZE VARIABLES
dim pic, newpic as picture

// CHECK IF AN IMAGE WAS DROPPED ONTO THE CANVAS
if obj.FolderItemAvailable then

// ATTACH THE DROPPED IMAGE TO THE PICTURE OBJECT CALLED PIC
pic = picture.open(obj.FolderItem)

// RESIZE TO 512 X 512 AND SAVE
// CREATE A NEW 512 X 512 PICTURE OBJECT CALLED NEWPIC
newpic = new picture(512,512,32)

// DRAW PIC AT THE NEW SIZE INTO THE PICTURE OBJECT CALLED NEWPIC
newpic.graphics.drawpicture(pic, 0,0,512,512, 0,0,pic.width,pic.height)

dim f2 as New folderitem
f2=obj.FolderItem

Dim s As New Shell
s.mode = 0
s.Execute(“sips -s format png -Z 512 “+f2.shellpath+” --out 512.png”)[/code]

Did as you advised Dave, and this is what appeared:

And there is your entire problem… “CANNOT WRITE TO FILE”

try this

dim f3 as folderitem
f3=specialfolder.desktop.child("test.png")
s.Execute("sips -s format png -Z 512 "+f2.shellpath+" --out "+f3.shellpath)

still leave MSGBOX… I purposely made the output name different… so the error message will be more meaningful

also… try moving the “-Z 512” to right after the command (before the -s) should not matter, but all the examples I see show it that way

FINALLY (after all day and night) - I did as you just advised, and it now saves the png file :slight_smile:

Thank you ALL so much for all your help.
That was an experience I never wish to repeat :slight_smile:

just alter F3 to be the path you want and use the code above

Why on earth do you think this is tied to your computer ? ? ?

obj.FolderItem.ShellPath is very simply the ShellPath to the file the user drops onto your app. No need to summon another FolderItem …

Michel - I thought that after a 16 hour day of learning :slight_smile:
It is now working perfectly AND I NOW understand it.

Once again - Thank you all for your patience and help!

Michel… I think he just had his gimp mask on to tight today is all :slight_smile:

Glad you finally got it all working… Whew! :smiley: