This repository has been archived by the owner on Feb 24, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #8; Finally you can change the base density!
- Loading branch information
Geert Wille
committed
Sep 10, 2015
1 parent
acfd058
commit 0be45da
Showing
6 changed files
with
175 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Developer: Geert Wille | ||
|
||
@import 'library/main.js' | ||
|
||
var selection = context.selection, | ||
document = context.document, | ||
factors = [ | ||
{ | ||
folder: '', | ||
scale: 1.0, | ||
suffix: '', | ||
}, | ||
{ | ||
folder: '', | ||
scale: 2.0, | ||
suffix: '@2x', | ||
}, | ||
{ | ||
folder: '', | ||
scale: 3.0, | ||
suffix: '@3x', | ||
}, | ||
] | ||
; | ||
|
||
var home_folder = "/Users/" + NSUserName(); | ||
new AppSandbox().authorize(home_folder, function() { | ||
com.geertwille.main.updateBaseDensity(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"density-scale":3} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
var writeTextToFile = function(text, filePath) { | ||
var t = [NSString stringWithFormat:@"%@", text], | ||
f = [NSString stringWithFormat:@"%@", filePath]; | ||
return [t writeToFile:f atomically:true encoding:NSUTF8StringEncoding error:nil]; | ||
} | ||
|
||
var readTextFromFile = function(filePath) { | ||
var fileManager = [NSFileManager defaultManager]; | ||
if([fileManager fileExistsAtPath:filePath]) { | ||
return [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; | ||
} | ||
return nil; | ||
} | ||
|
||
var jsonFromFile = function(filePath, mutable) { | ||
var data = [NSData dataWithContentsOfFile:filePath]; | ||
var options = mutable == true ? NSJSONReadingMutableContainers : 0 | ||
return [NSJSONSerialization JSONObjectWithData:data options:options error:nil]; | ||
} | ||
|
||
var saveJsonToFile = function(jsonObj, filePath) { | ||
writeTextToFile(stringify(jsonObj), filePath); | ||
} | ||
|
||
var stringify = function(obj, prettyPrinted) { | ||
var prettySetting = prettyPrinted ? NSJSONWritingPrettyPrinted : 0, | ||
jsonData = [NSJSONSerialization dataWithJSONObject:obj options:prettySetting error:nil]; | ||
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; | ||
} | ||
|
||
var createTempFolderNamed = function(name) { | ||
var tempPath = getTempFolderPath(name); | ||
createFolderAtPath(tempPath); | ||
return tempPath; | ||
} | ||
|
||
var getTempFolderPath = function(withName) { | ||
var fileManager = [NSFileManager defaultManager], | ||
cachesURL = [[fileManager URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask] lastObject], | ||
withName = (typeof withName !== 'undefined') ? withName : (Date.now() / 1000), | ||
folderName = [NSString stringWithFormat:"%@", withName]; | ||
return [[cachesURL URLByAppendingPathComponent:folderName] path]; | ||
} | ||
|
||
var createFolderAtPath = function(pathString) { | ||
var fileManager = [NSFileManager defaultManager]; | ||
if([fileManager fileExistsAtPath:pathString]) return true; | ||
return [fileManager createDirectoryAtPath:pathString withIntermediateDirectories:true attributes:nil error:nil]; | ||
} | ||
|
||
var removeFileOrFolder = function(filePath) { | ||
[[NSFileManager defaultManager] removeItemAtPath:filePath error:nil]; | ||
} | ||
|
||
var readPluginPath = function() { | ||
var pluginFolder = context.scriptPath.match(/Plugins\/([\w -])*/)[0] + "/"; | ||
var sketchPluginsPath = context.scriptPath.replace(/Plugins([\w \/ -])*.sketchplugin$/, ""); | ||
|
||
return { | ||
sketchPluginsPath: sketchPluginsPath, | ||
pluginFolder: pluginFolder | ||
} | ||
} | ||
|
||
var helpers = { | ||
readTextFromFile: readTextFromFile, | ||
writeTextToFile: writeTextToFile, | ||
jsonFromFile: jsonFromFile, | ||
saveJsonToFile: saveJsonToFile, | ||
createFolderAtPath: createFolderAtPath, | ||
removeFileOrFolder: removeFileOrFolder, | ||
readPluginPath: readPluginPath | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters