• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: scripting Xcode to import images
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: scripting Xcode to import images


  • Subject: Re: scripting Xcode to import images
  • From: Shane Stanley <email@hidden>
  • Date: Tue, 07 Apr 2015 21:36:40 +1000

On 7 Apr 2015, at 8:29 pm, 2551 <email@hidden> wrote:

Does anyone know if it's possible to script this borathon of creating a new image sets in Xcode and importing all the required image sizes into the assets catalog?  

Find the project's .xcassets folder on your disk, create new .imageset folders containing the images, and write the details to Contents.json files also inside the .imageset folders. Use an existing one to find the format of the .json file. No need to ruffle Xcode's feathers.

I posted a couple of AS<-> JSON handlers a while back:

use framework "Foundation"

-- pass a string, list, record or number, and either a path to save the result to, or missing value to have it returned as text
on convertASToJSON:someASThing saveTo:posixPath
--convert to JSON data
set {theData, theError} to current application's NSJSONSerialization's dataWithJSONObject:someASThing options:0 |error|:(reference)
if theData is missing value then error (theError's localizedDescription() as text) number -10000
if posixPath is missing value then -- return string
-- convert data to a UTF8 string
set someString to current application's NSString's alloc()'s initWithData:theData encoding:(current application's NSUTF8StringEncoding)
return someString as text
else
-- write data to file
theData's writeToFile:posixPath atomically:true
return result as boolean -- returns false if save failed
end if
end convertASToJSON:saveTo:

-- pass either a POSIX path to the JSON file, or a JSON string; isPath is a boolean value to tell which
on convertJSONToAS:jsonStringOrPath isPath:isPath
if isPath then -- read file as data
set theData to current application's NSData's dataWithContentsOfFile:jsonStringOrPath
else -- it's a string, convert to data
set aString to current application's NSString's stringWithString:jsonStringOrPath
set theData to aString's dataUsingEncoding:(current application's NSUTF8StringEncoding)
end if
-- convert to Cocoa object
set {theThing, theError} to current application's NSJSONSerialization's JSONObjectWithData:theData options:0 |error|:(reference)
if theThing is missing value then error (theError's localizedDescription() as text) number -10000
-- we don't know the class of theThing for coercion, so...
if (theThing's isKindOfClass:(current application's NSArray)) as integer = 1 then
return theThing as list
else
return item 1 of (theThing as list)
end if
end convertJSONToAS:isPath:

Pass a sample Contents.json file to the first, to see what sort of AS record you need to build:

  --> {images:{{idiom:"mac", scale:"1x", filename:"command.png"}, {idiom:"mac", scale:"2x", filename:"email@hidden"}}, info:{version:1, author:"xcode"}}

Then use the second to write out the finished records.

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: scripting Xcode to import images
      • From: 2551 <email@hidden>
    • Re: scripting Xcode to import images
      • From: 2551 <email@hidden>
References: 
 >scripting Xcode to import images (From: 2551 <email@hidden>)

  • Prev by Date: scripting Xcode to import images
  • Next by Date: Re: scripting Xcode to import images
  • Previous by thread: scripting Xcode to import images
  • Next by thread: Re: scripting Xcode to import images
  • Index(es):
    • Date
    • Thread