Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Oct 20, 2017 10:20 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: applescript for executing terminal commands
PostPosted: Wed Apr 10, 2013 5:04 pm 
Offline

Joined: Fri Jan 08, 2010 9:59 am
Posts: 315
I am creating a utility for RS users to create musical notation based on ABC and the ABCm2ps tool.

Right now it works perfectly on Windows. I call a shell command to a bat file which then executes a series of console commands and this produces a png ready for use in my software. I'm a long-time window user so this is not a shock to me...

However, I'm pretty new to the mac and I was wondering how I would do this bat file in the mac? I've heard the term applescript bandied about and there is also RBscript... What sort of file executes terminal commands on the mac when called?

Here's the bat file contents:

@echo off
rem delete SReader1.mid
REM %1 is the running directory for this batch file
REM %2 is the abc file to convert

CD %1
abc2midi SReadermusic.abc
abc2abc SReadermusic.abc -n 2 -usekey +2
REM abcm2ps -v -s 0.6 -B2 -l %2
abcm2ps -v -s 1.0 -B2 %2
java -jar batik-rasterizer.jar out001.svg


in the windows folder that this is, there is the Batik library (which is Java which will convert SVG to PNGs)
and the windows version of abcm2ps, abcmidi.

I've created a folder for the apple version of my software with all the apple ABC programs in it.

What would I use in place of the BAT file?


Top
 Profile  
Reply with quote  
 Post subject: Re: applescript for executing terminal commands
PostPosted: Wed Apr 10, 2013 5:21 pm 
Offline
User avatar

Joined: Sun Aug 12, 2007 10:10 am
Posts: 1086
Location: Boiling Springs, SC
seanclancy wrote:
I am creating a utility for RS users to create musical notation based on ABC and the ABCm2ps tool.

Right now it works perfectly on Windows. I call a shell command to a bat file which then executes a series of console commands and this produces a png ready for use in my software. I'm a long-time window user so this is not a shock to me...

However, I'm pretty new to the mac and I was wondering how I would do this bat file in the mac? I've heard the term applescript bandied about and there is also RBscript... What sort of file executes terminal commands on the mac when called?

Here's the bat file contents:

@echo off
rem delete SReader1.mid
REM %1 is the running directory for this batch file
REM %2 is the abc file to convert

CD %1
abc2midi SReadermusic.abc
abc2abc SReadermusic.abc -n 2 -usekey +2
REM abcm2ps -v -s 0.6 -B2 -l %2
abcm2ps -v -s 1.0 -B2 %2
java -jar batik-rasterizer.jar out001.svg


in the windows folder that this is, there is the Batik library (which is Java which will convert SVG to PNGs)
and the windows version of abcm2ps, abcmidi.

I've created a folder for the apple version of my software with all the apple ABC programs in it.

What would I use in place of the BAT file?


an SH file :-) you can also

Dim myShell as new Shell

Shell.execute "abc2midi SReadermusic.abc"
Shell.execute "abc2abc SReadermusic.abc -n 2 -usekey +2"
Shell.execute "REM abcm2ps -v -s 0.6 -B2 -l %2"
Shell.execute "abcm2ps -v -s 1.0 -B2 %2"
Shell.execute "java -jar batik-rasterizer.jar out001.svg"

without creating any files... especially if the program will be installed using an installer this would be the best method since mac and windows no longer allows files to be written in the program folder/applications directory... pick a location for the creation of files such as Special.ApplicationData (a member of FolderItem) :-)

_________________
Matthew A. Combatti
Real Studio 2012 r1.2

Visit Xojo Developer's Spot!
Systems I Use:
Windows XP/Windows Vista/Windows Server 2008 r2/Windows 7/Windows 8
Mac OSX 10.5/Mac OSX 10.6/Mac OSX Server/Ubuntu/Debian/Suse/Red Hat/
Windows Server 2011/CentOS 5.4 /ReactOS/SimOS

~All Xojo Compatible~


Top
 Profile  
Reply with quote  
 Post subject: Re: applescript for executing terminal commands
PostPosted: Wed Apr 10, 2013 5:33 pm 
Offline

Joined: Fri Jan 08, 2010 9:59 am
Posts: 315
My folder will be sitting in the library/application support/Guitar/ABC/MACConvert folder
so there will be no qualms about writing to it.



these abc apps are libraries and are accessed via terminal commands - they aren't installed (which is very cool). You just have them in the folder and they work.

Naturally, I will get absolute filepaths to each of the apps and the files I need to retrieve.


So,these shell commands you suggested would run like like terminal commands?


Top
 Profile  
Reply with quote  
 Post subject: Re: applescript for executing terminal commands
PostPosted: Wed Apr 10, 2013 6:38 pm 
Offline
User avatar

Joined: Sun Aug 12, 2007 10:10 am
Posts: 1086
Location: Boiling Springs, SC
seanclancy wrote:
My folder will be sitting in the library/application support/Guitar/ABC/MACConvert folder
so there will be no qualms about writing to it.



these abc apps are libraries and are accessed via terminal commands - they aren't installed (which is very cool). You just have them in the folder and they work.

Naturally, I will get absolute filepaths to each of the apps and the files I need to retrieve.


So,these shell commands you suggested would run like like terminal commands?


Shell is direct access to the terminal. Don't forget to use myshell.close when all commands are sent. (replacing myshell with whatever you declares as new shell) or you could run into errors. You can also use myshell.result to check each commands terminal output to check for errors. Review the shell documentation. There is active and inactive shell which either keeps the same terminal (shell) running between commands, but you should be ok without knowing this aspect using the example above. As always if you run into an issue, we're here. :-)

_________________
Matthew A. Combatti
Real Studio 2012 r1.2

Visit Xojo Developer's Spot!
Systems I Use:
Windows XP/Windows Vista/Windows Server 2008 r2/Windows 7/Windows 8
Mac OSX 10.5/Mac OSX 10.6/Mac OSX Server/Ubuntu/Debian/Suse/Red Hat/
Windows Server 2011/CentOS 5.4 /ReactOS/SimOS

~All Xojo Compatible~


Top
 Profile  
Reply with quote  
 Post subject: Re: applescript for executing terminal commands
PostPosted: Thu Apr 11, 2013 5:44 am 
Offline

Joined: Fri Jan 08, 2010 9:59 am
Posts: 315
I tried using the terminal in the folder with abcm2ps and when I ran it I got
Permission denied...

Will these shell command run it without errors - or regardless of permissions?


Top
 Profile  
Reply with quote  
 Post subject: Re: applescript for executing terminal commands
PostPosted: Thu Apr 11, 2013 9:40 pm 
Offline
User avatar

Joined: Sun Aug 12, 2007 10:10 am
Posts: 1086
Location: Boiling Springs, SC
seanclancy wrote:
I tried using the terminal in the folder with abcm2ps and when I ran it I got
Permission denied...

Will these shell command run it without errors - or regardless of permissions?


Just for fun, move your abc files outside of library:applications to a user owned path or elevate your permissions using "sudo". See how that works...

_________________
Matthew A. Combatti
Real Studio 2012 r1.2

Visit Xojo Developer's Spot!
Systems I Use:
Windows XP/Windows Vista/Windows Server 2008 r2/Windows 7/Windows 8
Mac OSX 10.5/Mac OSX 10.6/Mac OSX Server/Ubuntu/Debian/Suse/Red Hat/
Windows Server 2011/CentOS 5.4 /ReactOS/SimOS

~All Xojo Compatible~


Top
 Profile  
Reply with quote  
 Post subject: Re: applescript for executing terminal commands
PostPosted: Fri Apr 12, 2013 4:43 am 
Offline

Joined: Fri Jan 08, 2010 9:59 am
Posts: 315
I found a way...It works with terminal so it should work with the shell commands

chmod +x abcm2ps
chmod +x abc2midi

then ./abcm2ps -v -s 1.0 -B2 Sreader.abc

so, just to be sure -
Is this the syntax I need to use to execute the shell in the correct folder?
(the folder is call "MACconvert)". that's where my abcm2ps application is that I want to shell :)

dim f as folderitem = specialfolder.applicationdata.child("My Guitar program").child("ABC").child("MACconvert)
Myshell.execute chr(34)+f.absolutepath +chr(34) + " ./abcm2ps -v -s 1.0 -B2 Sreader.abc"

My the way, I checked out the paypal payment example at your RSdeveloper site :)
My customers will be paying via paypal. Could Imake a suggestion that you include a pay via paypal option as well?
I, like many customers don't have credit cards and I do all my online purchasing via my paypal account.
Also, I ran in a head not valid error when I went to run it.
I know that Paypal can send a notification out to a server when a payment is confirmed. Does this also happen with your example project?
I was thinking of doing this for my app.


Top
 Profile  
Reply with quote  
 Post subject: Re: applescript for executing terminal commands
PostPosted: Fri Apr 12, 2013 9:03 am 
Offline
User avatar

Joined: Sun Aug 12, 2007 10:10 am
Posts: 1086
Location: Boiling Springs, SC
To use the PayPal class you will need supply your sandbox information when testing and setup the sandbox for the instant payments..I believe PayPal now charges $30/month for that service. Easier (moreso freely..and if a desktop app) you could directly embed the PayPal payment URL and use showurl to open payment window in the users default browser..then, if you use an apn setup, have the payment confirmation submitted to a URL location of your choice and save the confirmation to the website (file or db)...and the application can check using the httpsocket class to verify or deny if the payment has been made..There are a million ways to do it, all depending on what the software is meant to do. (any of which I'd be glad to help you get running).

By the way, if you are using the terminal in a shell class, I believe you may run into complications using the ASCII chr(34) and absolutepath.. You may want to omit the quotes and use folderitem.shellpath. This option is the system default choice and will concatenate the path (which will take care of any spaces if present in the path..which would require quotes otherwise). But yes, your syntax is perfect otherwise :-) The chmod x will only work if the user has root privlidges to start (so probably wouldn't work in a school or library environment where restrictions are limited)... There are functions to check if the application has elevated privlidges at startup, and if not, automatically elevate them... But your code should start working with what you have. Remember that a Developer's machine generally has less restrictions than the common user's as the system adapts and is altered by the developer changing settings and permissions. You have a great start, plow through the core code to get it working, then focus on improvement and adding functionalities :-) as always, here to help...

_________________
Matthew A. Combatti
Real Studio 2012 r1.2

Visit Xojo Developer's Spot!
Systems I Use:
Windows XP/Windows Vista/Windows Server 2008 r2/Windows 7/Windows 8
Mac OSX 10.5/Mac OSX 10.6/Mac OSX Server/Ubuntu/Debian/Suse/Red Hat/
Windows Server 2011/CentOS 5.4 /ReactOS/SimOS

~All Xojo Compatible~


Top
 Profile  
Reply with quote  
 Post subject: Re: applescript for executing terminal commands
PostPosted: Fri Apr 12, 2013 9:23 am 
Offline

Joined: Fri Jan 08, 2010 9:59 am
Posts: 315
Thanks Simulanics,

Do you have a code snippet to automatically enable privileges?
My software is going have some schools interested :)

I downloaded your realdeveloper app and went through every interesting snippet and project...
You're doing a really great job there for all RS users!

I got the code snippet for capturing the windows screen. This is actually something that I've been needing!
Is there a way to do a simple plugin-less screenshot in Mac (have it triggered in a realstudio event?)

The audio example does work unfortunately (is not even listed in the downloadables)


Top
 Profile  
Reply with quote  
 Post subject: Re: applescript for executing terminal commands
PostPosted: Fri Apr 12, 2013 12:19 pm 
Offline
User avatar

Joined: Sun Aug 12, 2007 10:10 am
Posts: 1086
Location: Boiling Springs, SC
seanclancy wrote:
Thanks Simulanics,

Do you have a code snippet to automatically enable privileges?
My software is going have some schools interested :)

I downloaded your realdeveloper app and went through every interesting snippet and project...
You're doing a really great job there for all RS users!

I got the code snippet for capturing the windows screen. This is actually something that I've been needing!
Is there a way to do a simple plugin-less screenshot in Mac (have it triggered in a realstudio event?)

The audio example does work unfortunately (is not even listed in the downloadables)
I've been meaning to add Mac and Linux to screenshots but in the meantime here's the reference

http://developer.apple.com/library/mac/ ... ure.1.html

This is also shell-able... Use -c to capture to clipboard and manipulate from there after loading into a picture object :-)

I'll write a quick module for you to check privlidges today :-) (give me an hr or so to upload)

_________________
Matthew A. Combatti
Real Studio 2012 r1.2

Visit Xojo Developer's Spot!
Systems I Use:
Windows XP/Windows Vista/Windows Server 2008 r2/Windows 7/Windows 8
Mac OSX 10.5/Mac OSX 10.6/Mac OSX Server/Ubuntu/Debian/Suse/Red Hat/
Windows Server 2011/CentOS 5.4 /ReactOS/SimOS

~All Xojo Compatible~


Top
 Profile  
Reply with quote  
 Post subject: Re: applescript for executing terminal commands
PostPosted: Fri Apr 12, 2013 1:03 pm 
Offline

Joined: Fri Jan 08, 2010 9:59 am
Posts: 315
Well, you're a total legend!

I wonder if you'd mind if my folder for writing music notation with an open source example could be hosted on your site!

I get around to that after I've finished my program (3+ years and 2 months to go!)


Top
 Profile  
Reply with quote  
 Post subject: Re: applescript for executing terminal commands
PostPosted: Fri Apr 12, 2013 1:25 pm 
Offline
User avatar

Joined: Sun Aug 12, 2007 10:10 am
Posts: 1086
Location: Boiling Springs, SC
seanclancy wrote:
Well, you're a total legend!

I wonder if you'd mind if my folder for writing music notation with an open source example could be hosted on your site!

I get around to that after I've finished my program (3+ years and 2 months to go!)


Of course, I am all for helping the community and members. Real Software, Inc. has been great to me, so I can only return the favor :-) At realdevspot.com/realstudiodevspot.com I also offer free developer hosting for testing and development of web applications (If you have web edition and need a 'play-ground'.

Try this function for administrator privileged and let me know how it works...I'm currently driving in the car, so this hasn't been tested and was written on my iphone on the side of the road (it's going to take me a little over the estimated hr to get home...) :-)

Function IsAdministrator() As Boolean
#If TargetWin32 Then
Declare Function IsUserAnAdmin Lib "shell32" As Integer
if IsUserAnAdmin = 0 then
return false
else
return true
end if
#elseif TargetMacOS then
Dim isadmin as new shell
isadmin.Execute chr(34) +"80" + chr(34) + " is in (do shell script " + chr(34) +"id -G"+chr(34) + ")"
if trim(isadmin.Result) = "true" then
return true
else
return false
end if
#elseif TargetLinux then
Dim isadmin as new shell
isadmin.Execute "whoami"
if trim(isadmin.Result) = "root" then
return true
else
return false
end if
#endif
End Function


If the value returned is false, you can prompt a mac user to enter a username and password (in a box you create)then use the following applescript to elevate permissions if needed...

do shell script "command" user name "me" password "mypassword" with administrator privileges


Windows...you can only prompt with a msgbox stating "Please run this application as an Administrator"...although, if your application was installed (obviously) by an administrator...this will not effect you and can be ommitted (although great for re-use in future applications :-)) There is an option in windows to use the gettoken api...although it will return an error if UAC is enabled on the Windows machine...so stick with the shell32 api used above (I figure someone will reply here about gettoken..so that's my reasoning for sticking with the isuseranadmin api above)

_________________
Matthew A. Combatti
Real Studio 2012 r1.2

Visit Xojo Developer's Spot!
Systems I Use:
Windows XP/Windows Vista/Windows Server 2008 r2/Windows 7/Windows 8
Mac OSX 10.5/Mac OSX 10.6/Mac OSX Server/Ubuntu/Debian/Suse/Red Hat/
Windows Server 2011/CentOS 5.4 /ReactOS/SimOS

~All Xojo Compatible~


Top
 Profile  
Reply with quote  
 Post subject: Re: applescript for executing terminal commands
PostPosted: Fri Apr 12, 2013 3:51 pm 
Offline

Joined: Fri Jan 08, 2010 9:59 am
Posts: 315
You wrote this on the side of the road?

Are you sure you're not a cyborg? Surely to remember all that syntax, it must be 2nd nature!

Right now, I'm programming in Windows, and I don't need to run anything as administrator (there avoiding the horrible yellow pop-up of doom)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group