Viewing *.PNG, *.PDF and *.JPG on MacBook with m1

Mac OSX specific forum
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Viewing *.PNG, *.PDF and *.JPG on MacBook with m1

Post by Lord »

Hi!

I'm using (still) PB 6.00 LTS C-Backend (MacOS X - arm 64) on a MacBook.
This is my first effort to convert one of my Win7 programs to Mac.

My current problem is to display above mentioned files with on board apps.
My attempt to display the files like I did on Windows didn't work.

Code: Select all

Pgm=RunProgram(File, "", "", #PB_Program_Open)
File is a string variable that holds the complete path to the wanted file on a USB-Stick.

How can I utilize an on board viewer (or different viewers) for these files?
I just want to launch these apps, use them and then close them:

Code: Select all

    If Pgm
      KillProgram(Pgm)
      Pgm=0
    EndIf
Any help is appreciated.
Image
Fred
Administrator
Administrator
Posts: 18220
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Viewing *.PNG, *.PDF and *.JPG on MacBook with m1

Post by Fred »

IIRC, you need to use "open" command like

Code: Select all

Pgm=RunProgram("open", File, "", #PB_Program_Open)
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 460
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Viewing *.PNG, *.PDF and *.JPG on MacBook with m1

Post by Mindphazer »

Or you can specify the application name you want to use to visualize your images (Preview for example) like this :

Code: Select all

PV.s = Chr(34) + "Preview" + Chr(34)
Pgm = RunProgram("open", "-a " + PV + " " + File, "")
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: Viewing *.PNG, *.PDF and *.JPG on MacBook with m1

Post by Lord »

Hi Fred!
Fred wrote: Wed Dec 20, 2023 11:39 am IIRC, you need to use "open" command like

Code: Select all

Pgm=RunProgram("open", File, "", #PB_Program_Open)
Thank you for your answer.

It is not mentioned in the documentations for PB 6.00 for Mac that the first
parameter must be an "open" and not a file name.
Using "open", a picture (jpg/png) is viewed.
But...
1. A PDF-File is not viewed
2. KillProgram(Pgm) does not close a viewed picture

Do I still something wrong?
Image
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: Viewing *.PNG, *.PDF and *.JPG on MacBook with m1

Post by Lord »

Hi Mindphazer!
Mindphazer wrote: Wed Dec 20, 2023 11:51 am Or you can specify the application name you want to use to visualize your images (Preview for example) like this :

Code: Select all

PV.s = Chr(34) + "Preview" + Chr(34)
Pgm = RunProgram("open", "-a " + PV + " " + File, "")
Also thank you for your answer.
I first have to explorer what are the app-names for the corresponding file typ.
Is it maybe "Vorschau" for german version?
If so, what may be the app name for viewing pdf files?
What stands the "-a" for?
Image
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 460
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Viewing *.PNG, *.PDF and *.JPG on MacBook with m1

Post by Mindphazer »

Lord wrote: Wed Dec 20, 2023 1:13 pm Also thank you for your answer.
I first have to explorer what are the app-names for the corresponding file typ.
Is it maybe "Vorschau" for german version?
If so, what may be the app name for viewing pdf files?
What stands the "-a" for?
Well, you can list the real names of applications by typing, in a new terminal window

Code: Select all

ls -li /System/Applications/
I guess you will see Preview.app, which is the real name of your "Vorschau" application you have in the Finder
All applications have an extention ".app"
The "open" command is used to open a file, and the -a stands for "application", when you want to open an application
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 460
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Viewing *.PNG, *.PDF and *.JPG on MacBook with m1

Post by Mindphazer »

Lord wrote: Wed Dec 20, 2023 1:08 pm
2. KillProgram(Pgm) does not close a viewed picture

Do I still something wrong?
I think you have to kill the process launched by the "open" command. But I don't know how to do that yet
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: Viewing *.PNG, *.PDF and *.JPG on MacBook with m1

Post by Lord »

Mindphazer wrote: Wed Dec 20, 2023 1:29 pm...
Well, you can list the real names of applications by typing, in a new terminal window

Code: Select all

ls -li /System/Applications/
I guess you will see Preview.app, which is the real name of your "Vorschau" application you have in the Finder
All applications have an extention ".app"
The "open" command is used to open a file, and the -a stands for "application", when you want to open an application
OK. "Preview" aka "Vorschau" is the app to view pictures.
But "Preview" is also used to view a PDF. If I open in Finder
a PDF file, "Preview" ist launched and shows the PDF.
But RunProgram() does not launch a PDF, only my JPG/PNG.
I tried both of your variants of RunProgram(). No success.
Image
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 460
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Viewing *.PNG, *.PDF and *.JPG on MacBook with m1

Post by Mindphazer »

Lord wrote: Wed Dec 20, 2023 2:44 pm OK. "Preview" aka "Vorschau" is the app to view pictures.
But "Preview" is also used to view a PDF. If I open in Finder
a PDF file, "Preview" ist launched and shows the PDF.
But RunProgram() does not launch a PDF, only my JPG/PNG.
I tried both of your variants of RunProgram(). No success.
Weird. I've just tried with a simple pdf file
I copied it in my Documents directory
Then i ran that code :

Code: Select all

File.s = GetUserDirectory(#PB_Directory_Documents) + "test.pdf"
Pgm = RunProgram("open", File, "")
And it works
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: Viewing *.PNG, *.PDF and *.JPG on MacBook with m1

Post by Lord »

It is working! Kind of...

What did I do?
I enclosed the filename including the path in double quotes
(most of PDF-filenames included spaces, pics don't have).
And I removed the Killprogram() part. So the Pic/PDF has to
be closed manually.

Thanks for helping!
Image
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 460
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Viewing *.PNG, *.PDF and *.JPG on MacBook with m1

Post by Mindphazer »

Oh yeah, the eternal problem with spaces in filenames !!!
Glad it works !
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
infratec
Always Here
Always Here
Posts: 7618
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Viewing *.PNG, *.PDF and *.JPG on MacBook with m1

Post by infratec »

Btw.: 'open' is a filename. ('type open' in a terminal and it shows you the location of it)

It is like 'cmd' to start something in a windows shell.
It is a program which decides what to do with the given file.

In Linux you use 'xdg-open' to achieve the same.
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: Viewing *.PNG, *.PDF and *.JPG on MacBook with m1

Post by Lord »

Hi infratec!
infratec wrote: Wed Dec 20, 2023 10:17 pm Btw.: 'open' is a filename. ('type open' in a terminal and it shows you the location of it)

It is like 'cmd' to start something in a windows shell.
It is a program which decides what to do with the given file.

In Linux you use 'xdg-open' to achieve the same.
Thank you for your explanation.
Is there a 'counterpart' to "open"?
Maybe like this (doesn't work):

Code: Select all

PV.s = Chr(34) + "Preview" + Chr(34)
Pgm = RunProgram("close", "-a " + PV, "")
I still want to close the opened window of "preview".
Image
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 460
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Viewing *.PNG, *.PDF and *.JPG on MacBook with m1

Post by Mindphazer »

Hi Lord,

you can use the pkill command :

Code: Select all

RunProgram("pkill", PV, "")
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: Viewing *.PNG, *.PDF and *.JPG on MacBook with m1

Post by Lord »

Hi Mindphazer!
Thank you for helping again.
Mindphazer wrote: Thu Dec 21, 2023 12:06 pm...
you can use the pkill command :

Code: Select all

RunProgram("pkill", PV, "")
Yes, after executing this command, the "Preview" is closed.
But...
is a differentr picture opened with this above mentioned code, the picture
is not opened. Only second call shows the new picture ...
... and the first picture is also shown. There are two opened windows!

I think I stay for the moment with "let the user close the picture".
Image
Post Reply