Tuesday, October 1, 2013

Send Mail with multiple attachments to multiple recipients through AppleScript !



#Read file for mail body
set filePath to "/Users/......../MailBodyText.txt"
set theContent to (read filePath)

                 OR

#Compose mail body
set theContent to "Hi,

New build is available. Please find the details below:
Version: 1.1.1
URL:http://...........ipa

Detailed release note is attached for your reference.

Regards,
Dev-Team
"

#set file for attachment
set theAttachment1 to POSIX file "/Users/............/release_notes.xls"

#set Another attachment for latest log file
set attachFilePath to "/Users/....../builds/" & LatestFolderName & "/log"
set theAttachment2 to POSIX file attachFilePath


#Set Recipients
set nameList to {"Archana Chaurasia", "Recipient2", "Recipient3"}
set addressList to {"archana.2207@gmail.com", "Recipient2@test.com", "Recipient3@test.com"}

#Mail Tell Block
tell application "Mail"
           #Create the message
           set theMessage to make new outgoing message with properties {subject:releaseVersioncontent:theContentvisible:true}
           #Set a recipient
           tell theMessage
              make new attachment with properties {file name:theAttachment1at after the last paragraph
              make new attachment with properties {file name:theAttachment2at after the last paragraph
              repeat with i from 1 to count nameList
                        make new to recipient at end of to recipients with properties {name:item i of nameListaddress:item i of addressList}
              end repeat
#Send the Message
            send
            end tell

end tell

Monday, September 30, 2013

Read values of properties from plist through AppleScript !

#Read Bundle Version from info.plist through AppleScript !



set the plistfile_path to "/Users/................/AppName-Info.plist"

tell application "System Events"
set p_list to property list file (plistfile_path)
set releaseVersion to value of property list item "CFBundleVersion" of p_list
end tell

Get log file from latest folder through AppleScript !

#This AppleScript is for get latest log file generated during automatic build server.

set sourceFolder to "Users:....:.....:targetFolder"

property the_path : "/Users/..../.../targetFolder"
set theFolder to (POSIX file the_pathas alias

tell application "Finder"
set itemGroup to sort (get every folder of theFolderby creation date
set LatestFolder to (get first item of itemGroup)
set LatestFolderName to LatestFolder's name
end tell

set latestFilePath to "/Users/..../..../targetFolder/" & LatestFolderName & "/log"


#This AppleScript is for get latest folder and it's name.


set sourceFolder to "Users:....:.....:targetFolder"

property the_path : "/Users/..../.../targetFolder"
set theFolder to (POSIX file the_pathas alias

tell application "Finder"
set itemGroup to sort (get every folder of theFolderby creation date
set LatestFolder to (get first item of itemGroup)
set LatestFolderName to LatestFolder's name
end tell


Create ipa and plist file and upload files on server for Enterprise Application through Terminal !

cd "Applications path"

#Compile the build

xcodebuild -target AppTargetName -sdk iphoneos -configuration Release

#Archive the build

/usr/bin/xcrun -sdk iphoneos PackageApplication -v $applicationPath -o $ipaPath --sign Barclays --embed $mobileprovisionPath


#create the plist

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
<key>kind</key>
<string>software-package</string>
<key>url</key>
<string>$urlForIpa</string>
</dict>
</array>
<key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>$bundleIdentifier</string>
<key>bundle-version</key>
<string>$bundleVersion</string>
<key>kind</key>
<string>software</string>
<key>title</key>
<string>AppName</string>
</dict>
</dict>
</array>
</dict>
</plist>" > "projectName.plist"

                

#upload files on server

Below values depends on your server inputs values !

curl --form ipa=@$ipaPath --form plist=@$plistPath --form os=$os --form branch=$branch --form type=$type --form version=$bundleVersion --form file_size=22MB --form info=$bundleVersion --form releasenotes=@$releasenotes --form smartphones=$smartphones --form tablets=$tablets $urlToUploadfiles



Thursday, May 16, 2013

How to  know device type (Simulator, iPhone, iPod, iPad, iPad mini, Apple TV) programmatically ?
OR
How to  know device model (iPad1, iPad2... etc) or (iPhone, iPhone4s...etc) programmatically ?



#import <sys/utsname.h>

struct utsname systemInfo;
uname(&systemInfo);

NSString *modelName = [NSString stringWithCString:systemInfo.machine
                                         encoding:NSUTF8StringEncoding];

NSString *machineName = [NSString stringWithCString:systemInfo.machine
                                           encoding:NSUTF8StringEncoding];


NSString *modelNumber = @"?";

//Simulator

if([modelName isEqualToString:@"i386"] || [modelName isEqualToString:@"x86_64"]) {
    modelName = @"iPhone Simulator";
}

//iPhone

else if([modelName isEqualToString:@"iPhone1,1"]) {
    modelName = @"iPhone";
    modelNumber = @"A1203";
}
else if([modelName isEqualToString:@"iPhone1,2"]) {
    modelName = @"iPhone 3G";
    modelNumber = @"A1241/A1324";
}
else if([modelName isEqualToString:@"iPhone2,1"]) {
    modelName = @"iPhone 3GS";
    modelNumber = @"A1303/A1325";
}
else if([modelName isEqualToString:@"iPhone3,1"]) {
    modelName = @"iPhone 4 (GSM)";
    modelNumber = @"A1332";
}
else if([modelName isEqualToString:@"iPhone3,2"]) {
    modelName = @"iPhone 4 GSM Rev A";
    modelNumber = @"?";
}
else if([modelName isEqualToString:@"iPhone3,3"]) {
    modelName = @"iPhone 4 (CDMA)";
    modelNumber = @"A1349";
}
else if([modelName isEqualToString:@"iPhone4,1"]) {
    modelName = @"iPhone 4S";
    modelNumber = @"A1387/A1431";
}
else if([modelName isEqualToString:@"iPhone5,1"]) {
    modelName = @"iPhone 5 (GSM)";
    modelNumber = @"A1428";
}
else if([modelName isEqualToString:@"iPhone5,2"]) {
    modelName = @"iPhone 5 (GSM+CDMA)";
    modelNumber = @"A1429/A1442";
}

//iPod touch

else if([modelName isEqualToString:@"iPod1,1"]) {
    modelName = @"iPod touch 1G";
    modelNumber = @"A1213";
}
else if([modelName isEqualToString:@"iPod2,1"]) {
    modelName = @"iPod touch 2G";
    modelNumber = @"A1288";
}
else if([modelName isEqualToString:@"iPod3,1"]) {
    modelName = @"iPod touch 3G";
    modelNumber = @"A1318";
}
else if([modelName isEqualToString:@"iPod4,1"]) {
    modelName = @"iPod touch 4G";
    modelNumber = @"A1367";
}
else if([modelName isEqualToString:@"iPod5,1"]) {
    modelName = @"iPod touch 5G";
    modelNumber = @"A1421";
}

//iPad

else if([modelName isEqualToString:@"iPad1,1"]) {
    modelName = @"iPad 1G";
    modelNumber = @"A1219/A1337";
}
else if([modelName isEqualToString:@"iPad2,1"]) {
    modelName = @"iPad 2 (WiFi)";
    modelNumber = @"A1395";
}
else if([modelName isEqualToString:@"iPad2,2"]) {
    modelName = @"iPad 2 (GSM)";
    modelNumber = @"A1396";
}
else if([modelName isEqualToString:@"iPad2,3"]) {
    modelName = @"iPad 2 (CDMA)";
    modelNumber = @"A1397";
}
else if([modelName isEqualToString:@"iPad2,4"]) {
    modelName = @"iPad 2 (WiFi + Rev A)";
    modelNumber = @"A1395";
}
else if([modelName isEqualToString:@"iPad3,1"]) {
    modelName = @"iPad 3 (WiFi)";
    modelNumber = @"A1416";
}
else if([modelName isEqualToString:@"iPad3,2"]) {
    modelName = @"iPad 3 (GSM+CDMA)";
    modelNumber = @"A1403";
}
else if([modelName isEqualToString:@"iPad3,3"]) {
    modelName = @"iPad 3 (GSM)";
    modelNumber = @"A1430";
}
else if([modelName isEqualToString:@"iPad3,4"]) {
    modelName = @"iPad 4 (WiFi)";
    modelNumber = @"A1458";
}
else if([modelName isEqualToString:@"iPad3,5"]) {
    modelName = @"iPad 4 (GSM)";
    modelNumber = @"A1459";
}
else if([modelName isEqualToString:@"iPad3,6"]) {
    modelName = @"iPad 4 (GSM+CDMA)";
    modelNumber = @"A1460";
}

//iPad mini

else if([modelName isEqualToString:@"iPad2,5"]) {
    modelName = @"iPad mini (WiFi)";
    modelNumber = @"A1432";
}
else if([modelName isEqualToString:@"iPad2,6"]) {
    modelName = @"iPad mini (GSM)";
    modelNumber = @"A1454";
}
else if([modelName isEqualToString:@"iPad2,7"]) {
    modelName = @"iPad mini (GSM+CDMA)";
    modelNumber = @"A1455";
}

//Apple TV, just for funn:)

else if([modelName isEqualToString:@"AppleTV2,1"]) {
    modelName = @"Apple TV 2G";
    modelNumber = @"A1378";
}
else if([modelName isEqualToString:@"AppleTV3,1"]) {
    modelName = @"Apple TV 3G";
    modelNumber = @"A1427";
}
else if([modelName isEqualToString:@"AppleTV3,2"]) {
    modelName = @"Apple TV 3G (Rev A)";
    modelNumber = @"A1469";
}

NSLog(@"Device model: %@/ %@",modelName,modelNumber);

Happy Coding :)