runprogram

Mac OSX specific forum
spacebuddy
Enthusiast
Enthusiast
Posts: 356
Joined: Thu Jul 02, 2009 5:42 am

runprogram

Post by spacebuddy »

Hey all,

when I use this command in terminal

/usr/local/bin/hear -d -i /Users/george/Downloads/notebook.mp3 > test.txt

It executes a program which converts a mp3 to text. This works.

When I try the purebasic code below I always get an error.


Code: Select all

Compiler = RunProgram("/usr/local/bin/hear", "-d -i /Users/george/Downloads/notebook.mp3 > test.txt", "",#PB_Program_Open | #PB_Program_Read)
  Output$ = ""
  If Compiler
    While ProgramRunning(Compiler)
      If AvailableProgramOutput(Compiler)
        Output$ + ReadProgramString(Compiler) + Chr(13)
      EndIf
    Wend
    Output$ + Chr(13) + Chr(13)
    Output$ + "Exitcode: " + Str(ProgramExitCode(Compiler))
    
    CloseProgram(Compiler) ; Close the connection to the program
  EndIf
  
  MessageRequester("Output", Output$)
can anyone tell me what I am doing wrong?

Thanks
User avatar
robertfern
User
User
Posts: 38
Joined: Fri Feb 02, 2018 10:33 pm
Location: New Jersey

Re: runprogram

Post by robertfern »

Where does someone get the program "here"?

Also, because you piped the output to test.txt, you can't get any output from the readProgramString command.
Mac OSX Ventura & Windows 10, PB 6.12
spacebuddy
Enthusiast
Enthusiast
Posts: 356
Joined: Thu Jul 02, 2009 5:42 am

Re: runprogram

Post by spacebuddy »

I found the problem. When the app is compiled it works, it ask for microphone access and folder.

In the IDE this does not happen. Since the IDE does not ask for access, it does not work.

So, how to ask for access in the IDE so I can still work on the program? :D

You can download hear from GitHub
https://github.com/sveinbjornt/hear

Thanks
AZJIO
Addict
Addict
Posts: 2143
Joined: Sun May 14, 2017 1:48 am

Re: runprogram

Post by AZJIO »

The path to the test.txt file is not specified. If you compile a program, then the working folder is where the executable file is located. If you are running from the IDE, the working folder may be the IDE directory.
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: runprogram

Post by Shardik »

spacebuddy wrote: Wed Nov 27, 2024 9:42 pm I found the problem. When the app is compiled it works, it ask for microphone access and folder.

In the IDE this does not happen. Since the IDE does not ask for access, it does not work.

So, how to ask for access in the IDE so I can still work on the program? :D
In which MacOS version did you try it? I had the same problem in the IDE with the requester for allowing access to the AddressBook contacts. On Sonoma and Sequoia I wasn't able to trigger the allowance requester in the IDE with PB 6.04 and 6.12. On Ventura and older it wasn't possible with PB 6.04 and 6.12, but the allowance requester was triggered using PB 5.73. Unfortunately PB 5.73 doesn't run anymore on Sonoma and Sequoia. After compiling an app the allowance requester for the app appears reliably on all MacOS and PB versions.
spacebuddy
Enthusiast
Enthusiast
Posts: 356
Joined: Thu Jul 02, 2009 5:42 am

Re: runprogram

Post by spacebuddy »

I am using sequoia Beta 4.

Would be nice to be able to change the info.plist in the IDE. This way you can add the permissions
while debugging the app.
User avatar
Piero
Addict
Addict
Posts: 865
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: runprogram

Post by Piero »

Doesn't it work from IDE if you assign the same permissions (of your app) to purebasic.app on system prefs (security & privacy)?

PS: initially (while reading 1st post) I thought the problem could be the ">"…
Anyway, when it's working on Terminal but not in PB:
viewtopic.php?p=613031#p613031
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: runprogram

Post by Shardik »

spacebuddy wrote: Thu Nov 28, 2024 4:56 pm Would be nice to be able to change the info.plist in the IDE. This way you can add the permissions
while debugging the app.
Unfortunately this wouldn't help. In
System settings > Privacy & Security > Microphone
you see the apps allowed to use the microphone. When running a PB program in the IDE, the PureBasic IDE has to be allowed to use the microphone and not the program running in the IDE. If you compile your PB program to an app and starting the app, a MacOS system requester will ask for allowance to use the microphone using the app's name.

To access my AddressBook via Contacts in the PureBasic IDE, I even tried to add PB to an entitlements file allowing access to the AddressBook and to com.apple.developer.contacts, but it didn't work. And I tried to add "Privacy - Contacts usage description" to the Info.plist of the PureBasic.app, but it also didn't work and after a new start of the PureBasic.app the file was reported to be corrupted, so that I had to replace the changed Info.plist by the previous unchanged one.

As already written until now I didn't find a solution to trigger the allowance requester in the PureBasic IDE of PB 6.04 and 6.12 in Sonoma and Sequoia. For further infos you may also take a look into my Contacts framework posting.
User avatar
Piero
Addict
Addict
Posts: 865
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: runprogram

Post by Piero »

I dunno sequoia, but if you grant perms to purebasic.app, the IDE (compile/run) app should inherit its perms, and AddressBook etc. should work if you grant "full disk access" to PB.app
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: runprogram

Post by Shardik »

Piero wrote: Fri Nov 29, 2024 11:44 am I dunno sequoia, but if you grant perms to purebasic.app, the IDE (compile/run) app should inherit its perms, and AddressBook etc. should work if you grant "full disk access" to PB.app
I just tested on Sequoia: "Full disk access" is enabled for "PureBasic 6.04 x64". But the access allowance requester is not triggered for my contacts example! For "Full disk access" it's possible to add new apps like "PureBasic.app" with a Plus-button, but in other categories like "Contacts" or "Microphone" a Plus-button doesn't exist. So you have no chance to add "PureBasic.app" manually to these categories. In these cases the only possibility to add the PureBasic IDE to "Contacts" or "Microphone" is an access requester being triggered by executing a program in the PureBasic IDE needing access to these categories! And as stated several times: this is currently not possible on Sonoma and Sequoia. And on Ventura and older only when executing this program in the IDE of PB 5.73...
User avatar
Piero
Addict
Addict
Posts: 865
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: runprogram

Post by Piero »

Please try to find a way via sys prefs; otherwise I will NEVER update to sequoia :o

PS/Edit: access allowance requester is not supposed to show up if you set perms (allow access) on sys prefs (in case try restarting Mac)
PPS: Setting sys prefs perms is like "doing it manually because allowance requester doesn't appear"

PPPS: Hope AZJIO will never read this; I wouldn't get a Mac after reading this
User avatar
Piero
Addict
Addict
Posts: 865
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: runprogram

Post by Piero »

Shardik wrote: Fri Nov 29, 2024 2:51 pmthis is currently not possible on Sonoma
Thanks for your explanation, was my fault (didn't remember the absence of the + in some prefs)

There seems to be a way, but I cannot test on Sonoma:
https://www.reluctant-tech-traveler.net ... c-access-1

There are also ways to reset prefs (that's how I solved when I had problems with perms dialog not appearing/working)

Code: Select all

sudo tccutil reset Microphone com.fantaisiesoftware.purebasicide
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: runprogram

Post by Shardik »

Shardik wrote: Fri Nov 29, 2024 10:33 am As already written until now I didn't find a solution to trigger the allowance requester in the PureBasic IDE of PB 6.04 and 6.12 in Sonoma and Sequoia.
I still didn't find a solution to trigger the allowance requester in the PureBasic IDE of PB 6.04, 6.12 and 6.20 Beta 3 using Asm and C backend in Sonoma and Sequoia. But I was able to trigger the allowance requester in Sonoma and Sequoia using the PureBasic IDE of PB 5.73 by adding the following Import at the top of the code:

Code: Select all

Import "-fno-pie" : EndImport
For a working example you should take a look into my example for accessing the CNContactStore. For Sonoma and Sequoia I also had to add the Import line above which unfortunately only works in PB 5.73 to trigger the allowance requester.

Piero wrote:There are also ways to reset prefs (that's how I solved when I had problems with perms dialog not appearing/working)

sudo tccutil reset Microphone com.fantaisiesoftware.purebasicide
Unfortunately using tccutil to clear the AddressBook permissions doesn't trigger afterwards the allowance requester in Sonoma and Sequoia when executing the contacts example in the IDE of PB 6.04, 6.12 and 6.20 Beta 3...
User avatar
Piero
Addict
Addict
Posts: 865
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: runprogram

Post by Piero »

Shardik wrote: Mon Jan 20, 2025 6:45 pm
Piero wrote:There are also ways to reset prefs (that's how I solved when I had problems with perms dialog not appearing/working)

sudo tccutil reset Microphone com.fantaisiesoftware.purebasicide
Unfortunately using tccutil to clear the AddressBook permissions doesn't trigger afterwards the allowance requester in Sonoma and Sequoia when executing the contacts example in the IDE of PB 6.04, 6.12 and 6.20 Beta 3...
But it can be useful, e.g., if you mess up allowing access with this risky sqlite method:
https://www.reluctant-tech-traveler.net ... c-access-1
Did you try?
In case, read all and be careful (Sonoma needs different commands)
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: runprogram

Post by Shardik »

Piero wrote: Thu Jan 23, 2025 1:32 pm But it can be useful, e.g., if you mess up allowing access with this risky sqlite method:
https://www.reluctant-tech-traveler.net ... c-access-1
Did you try?
No, I didn't try the sqlite method because it looks too risky and complicated. It's much less risky and error-prone in Sonoma and Sequoia to start a program in the IDE of PB 5.73 (with the posted Import line) for triggering the access requester. You only have to do it once. As soon as the access is allowed, your program can also be tested in the IDE of PB 6.04, 6.12 and 6.20.

I still hope to find an easy alternative with Apple Script and will report about it as soon as I have been successful.
Post Reply