Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Jul 23, 2014 9:05 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: MAS - need help creating script to modify Info.plist
PostPosted: Thu Dec 30, 2010 4:53 pm 
Offline

Joined: Tue Aug 05, 2008 9:51 pm
Posts: 48
I'm in the process of writing a shell script to inject and change values in the Info.plist file to prepare the app to go to the Mac App Store. From what I can tell, this has to be done outside of the RB compiler. I've got a partial shell script working. It successfully adds the 'LSApplicationCategoryType' to the file.

The problem I'm having is modifying value for the CFBundleVersion that is automatically created by RB.
It looks like this: 1.2.3.4.5 where:
1 = Major version
2 = Minor version
3 = Bug version
4 = StageCode
5 = NonRelease version
However, the Mac App Store only accepts 2-decimal point numbers (i.e. 1.2.3)

So, the goal is to read the existing CFBundleVersion number and manipulate it from 1.2.3.4.5 to 1.2.345 to allow it to be acceptable to the MAS. I also want to take the first part (1.2.3) and set that to the CFBundleShortVersionString value (also a Mac App Store requirement)-- I just need help with how to manipulate the strings to get the values required.

Here is the code I've got working so far:
#! /bin/sh
# The command below successfully gets the current working directory of the script:
# DIR=$(cd "$(dirname "$0")"; pwd)
# The 'Defaults Write' command sets new values to the Info.plist file.
#
# NOTE: change the 'MyAppName.app' to the name of your application,
# then save this text file with a '*.command' extension to make this work with your system.
#
# The next line successfully adds the LSApplicationCategoryType to Info.plist
defaults write "$(cd "$(dirname "$0")"; pwd)/MyAppName.app/Contents/Info" LSApplicationCategoryType public.app-category.business

# The CFBundleVersion must be a two decimal point number (1.2.3),
# but RealBasic supplies it as a 4 decimal point number (1.2.3.4.5)
# with 1 = Major ver, 2 = Minor ver, 3 = Bug ver, 4 = StageCode, 5 = NonRelease
# The goal is to extract the string to the left of 3rd 'dot',
# set that string to the CFBundleShortVersionString,
# then remove the 3rd and 4th 'dot' to end up with a modified CFBundleVersion formatted as 1.2.345
#
# The next line returns the full version number as created by RealBasic:
RBVERSION=(`defaults read "$(cd "$(dirname "$0")"; pwd)/MyAppName.app/Contents/Info" CFBundleVersion`)

# The next link returns the zero-based position of the first 'dot'
FIRSTDOT=`echo $RBVERSION | grep -c "."`


I'm stuck here. :oops:
I cannot figure out how to extract and build the strings I need in the shell script.
Any ideas? --- or --- Is there a better way to handle this?

_________________
REALStudio 2011R3
MacBook Air OS X Lion
Pilot eLog: http://www.sheald.net/flying


Top
 Profile  
 
 Post subject: Re: MAS - need help creating script to modify Info.plist
PostPosted: Thu Dec 30, 2010 9:35 pm 
Offline
User avatar

Joined: Thu Jul 27, 2006 6:31 pm
Posts: 1698
Location: Monterey, CA
In my post-build script I have CFBundleVersion mirror the value in CFBundleShortVersionString. I just implemented it in AppleScript so I could save it as a stand-alone app I run.

AppleScript:
set v to do shell script "defaults read 'path/to/Application.app/Contents/Info' CFBundleShortVersionString"
do shell script "defaults write 'path/to/Application.app/Contents/Info' CFBundleVersion " & v

_________________
ImagePlay Effects Library (40+ image effects in one open source module. No plugins, no dependencies, no restrictions.)
http://imageplay.sourceforge.net/


Top
 Profile  
 
 Post subject: Re: MAS - need help creating script to modify Info.plist
PostPosted: Fri Dec 31, 2010 1:34 am 
Offline

Joined: Mon Jul 24, 2006 4:06 am
Posts: 274
I took Tomis AppleScript and made an IDE script out of it:

dim theVersion as String = PropertyValue("App.LongVersion")
dim cmd as String
cmd = "defaults write " + CurrentBuildLocation + "/" + getShellString(CurrentBuildAppName) + ".app" + "/Contents/Info CFBundleVersion " + theVersion
dim theOutput as string = doShellCommand(cmd)
if theOutput <> "" then print theOutput

function getShellString(theString as String) as string
Return ReplaceAll(theString, " ", "\ ")
end Function

HTH

Trixi

_________________
Mit freundlichen Grüßen/Regards

Trixi Willius

http://www.mothsoftware.com
Mail Archiver X: The email archiving solution for professionals


Top
 Profile  
 
 Post subject: Re: MAS - need help creating script to modify Info.plist
PostPosted: Fri Jan 07, 2011 9:52 am 
Offline

Joined: Mon Nov 26, 2007 1:37 pm
Posts: 83
Just a heads up on using 'defaults write'. Be sure to use the 'sudo' command because, if you don't, you end up changing your Info.plist file permissions from 644 to 600. (And your app will be rejected)

sudo allows users to run programs with the security privileges of another user (i.e. root).


Top
 Profile  
 
 Post subject: Re: MAS - need help creating script to modify Info.plist
PostPosted: Fri Jan 07, 2011 1:03 pm 
Offline

Joined: Tue Aug 05, 2008 9:51 pm
Posts: 48
Thank you !

_________________
REALStudio 2011R3
MacBook Air OS X Lion
Pilot eLog: http://www.sheald.net/flying


Top
 Profile  
 
 Post subject: Re: MAS - need help creating script to modify Info.plist
PostPosted: Mon Jan 10, 2011 4:35 am 
Offline

Joined: Mon Jul 24, 2006 4:06 am
Posts: 274
Hi RBKanso,

thanks for the tip with the permissions. How do I use sudo with a build script? I get a nice error message when trying to do this.

sudo: no tty present and no askpass programm specified.

Trixi

_________________
Mit freundlichen Grüßen/Regards

Trixi Willius

http://www.mothsoftware.com
Mail Archiver X: The email archiving solution for professionals


Top
 Profile  
 
 Post subject: Re: MAS - need help creating script to modify Info.plist
PostPosted: Mon Jan 10, 2011 11:47 am 
Offline

Joined: Tue Aug 05, 2008 9:51 pm
Posts: 48
Instead of using sudo, I simply reset the file permissions as the last line of my script once all the modifications are complete using:
# =============================================
# == Reset permissions for the Info.plist file
# =============================================
echo "Setting Info.plist permissions..."
chmod 644 "$(cd "$(dirname "$0")"; pwd)/Your App Name.app/Contents/Info.plist"

_________________
REALStudio 2011R3
MacBook Air OS X Lion
Pilot eLog: http://www.sheald.net/flying


Top
 Profile  
 
 Post subject: Re: MAS - need help creating script to modify Info.plist
PostPosted: Sun Oct 09, 2011 12:36 pm 
Offline

Joined: Sun Jun 24, 2007 12:24 pm
Posts: 441
Location: Madrid
I know this is old, but I still wanted to do this via a shellscript.

This will provide the version with two digits precision:

defaults read "${DIR}/${APPNAME}.app/Contents/Info" CFBundleVersion| cut -f-3 -d"."


I currently do all modifications to the plist via a shellscript:

defaults write "${DIR}/${APPNAME}.app/Contents/Info" LSApplicationCategoryType public.app-category.Utilities
VERSION=$(defaults read "${DIR}/${APPNAME}.app/Contents/Info" CFBundleVersion| cut -f-3 -d".")
defaults write "${DIR}/${APPNAME}.app/Contents/Info" CFBundleVersion "${VERSION}"
defaults write "${DIR}/${APPNAME}.app/Contents/Info" NSHumanReadableCopyright "2011 Eduardo Gutierrez de Oliveira"
defaults write "${DIR}/${APPNAME}.app/Contents/Info" CFBundleIdentifier "info.eduo.$(echo ${APPNAME} | tr '[A-Z]' '[a-z]')"
defaults write "${DIR}/${APPNAME}.app/Contents/Info" LSMinimumSystemVersion "10.6.6"
chmod 644 "${DIR}/${APPNAME}.app/Contents/Info.plist"


As for your problem: You can use a variant of mine. Ugly but workable:
VERSION=$(defaults read "${DIR}/${APPNAME}.app/Contents/Info" CFBundleVersion)
VERSION=$(echo $(echo ${VERSION}|cut -f1 -d".")"."$(echo ${VERSION}|cut -f2 -d".")"."$(echo ${VERSION}|cut -f3 -d".")$(echo ${VERSION}|cut -f4 -d".")$(echo ${VERSION}|cut -f5 -d"."))
defaults write "${DIR}/${APPNAME}.app/Contents/Info" CFBundleVersion "${VERSION}"


I add the installation as well, for testing:

echo "${USERPASS}" | sudo -S installer -store -pkg "./${APPNAME}.pkg" -target /
open /Applications/"${APPNAME}".app

_________________
----
http://eduo.info/
http://gallery.eduo.info/
http://twitter.com/eduo/


Last edited by eduo on Sun Oct 09, 2011 2:37 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: MAS - need help creating script to modify Info.plist
PostPosted: Sun Oct 09, 2011 1:13 pm 
Offline
User avatar

Joined: Sat Nov 11, 2006 2:43 pm
Posts: 1221
Location: This poster has left the forums
Beatrix Willius wrote:
How do I use sudo with a build script? I get a nice error message when trying to do this.
sudo: no tty present and no askpass programm specified.


You can't use sudo with a build script. For security reasons you cannot pipe sudo to fill in the password.

I'm not even sure if build scripts are working again. We've had a number of bugs introduced and fixed and reintroduced in the past couple of years. I gave up using them.

_________________
%Invalidforumsignatureexception% user signature not found


Top
 Profile  
 
 Post subject: Re: MAS - need help creating script to modify Info.plist
PostPosted: Sun Oct 09, 2011 5:28 pm 
Offline

Joined: Sun Jun 24, 2007 12:24 pm
Posts: 441
Location: Madrid
pony wrote:
Beatrix Willius wrote:
How do I use sudo with a build script? I get a nice error message when trying to do this.
sudo: no tty present and no askpass programm specified.


You can't use sudo with a build script. For security reasons you cannot pipe sudo to fill in the password.

I'm not even sure if build scripts are working again. We've had a number of bugs introduced and fixed and reintroduced in the past couple of years. I gave up using them.


You can. It's just not recommended.

echo "${PASSWORD}" | sudo -S command_to_run

I do it in this script mainly because I couldn't care less about what happens if it gets out. I don't use it for anything else and this machine only does this.

_________________
----
http://eduo.info/
http://gallery.eduo.info/
http://twitter.com/eduo/


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

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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