var docRef = app.activeDocument;
var layers = docRef.layers;
var myLayer = layers["组5"]; //this defines the layer that you want to get the selection from
var myLayer = app.activeDocument.layers["组5"];
//alert(myLayer.layers);
docRef.selection = null;//这句是让你没有选中任何图层
for (var i=0;i<myLayer.layers.length;i++){
if (myLayer.layers[i].name=="图层"){ // alert(myLayer.layers[i].name=="图层");
// alert(myLayer.layers[i].name);
myLayer.layers[i].selected=true;
}
}
I have code like this, when in photoshop cs , that some sublayers have names equal to "图层" , then this sublayer should be selected, but doesn't work, who knows how to get them selected?
To my knowledge this is not possible with DOM, but Action Manager code will do the job:
var myName = "Layer 5";
deselectLayers(); // deselecting all layers first
traverseAllLayers(myName);
function selectByID(id)
{
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID('Lyr '), id);
desc.putReference(charIDToTypeID('null'), ref);
desc.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelection"));
executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
};
function deselectLayers()
{
var desc60 = new ActionDescriptor();
var ref30 = new ActionReference();
ref30.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
desc60.putReference(charIDToTypeID('null'), ref30);
executeAction(stringIDToTypeID('selectNoLayers'), desc60, DialogModes.NO);
};
function traverseAllLayers(n)
{
var ref0 = new ActionReference();
ref0.putProperty(charIDToTypeID('Prpr'), stringIDToTypeID('numberOfLayers'));
ref0.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var desc0 = executeActionGet(ref0);
var i = desc0.getInteger(stringIDToTypeID('numberOfLayers'));
for (i; i > 0; i--)
{
ref = new ActionReference();
ref.putIndex(charIDToTypeID('Lyr '), i);
var desc = executeActionGet(ref);
var layerName = desc.getString(charIDToTypeID('Nm '));
var Id = desc.getInteger(stringIDToTypeID( 'layerID' ));
if (layerName == n) selectByID(Id) // selecting by ID, adding to selection
}
}
Related
I need a photoshop script that selects all layers with the same name as the currently selected layer. The following code does the job:
if (app.documents.length > 0) {
activeDocument.suspendHistory('stuff', 'main()');
function main(){
if(!documents.length) return;
var myDoc = app.activeDocument;
var theName = myDoc.activeLayer.name;
var theResults = new Array;
selectAllLayers();
var selectedLayers = getSelectedLayersIdx();
for(var a = 0; a < selectedLayers.length; a++){
var thisName = layerName(Number(selectedLayers[a]));
if (thisName == theName) {
theResults.push(Number(selectedLayers[a]))
};
};
selectLayerByIndex(theResults[0], false);
for (var m = 1; m < theResults.length; m++) {
selectLayerByIndex(theResults[m], true);
};
}
};
function getSelectedLayersIdx(){
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count
var selectedLayers = new Array();
for(var i=0;i<c;i++){
try{
activeDocument.backgroundLayer;
selectedLayers.push( desc.getReference( i ).getIndex() );
}catch(e){
selectedLayers.push( desc.getReference( i ).getIndex()+1 );
}
}
}else{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
try{
activeDocument.backgroundLayer;
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
}catch(e){
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
}
}
return selectedLayers;
};
function selectAllLayers() {
var desc29 = new ActionDescriptor();
var ref23 = new ActionReference();
ref23.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc29.putReference( charIDToTypeID('null'), ref23 );
executeAction( stringIDToTypeID('selectAllLayers'), desc29, DialogModes.NO );
};
function layerName(idx){
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), idx);
var desc = executeActionGet(ref);
return desc.getString(stringIDToTypeID("name"));
};
function selectLayerByIndex(index,add){
add = undefined ? add = false:add
var ref = new ActionReference();
ref.putIndex(charIDToTypeID("Lyr "), index);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref );
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
try{
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message);
}
};
BUT, there is one problem, my files have a ton of layers and so it appears that this code must iterate through them all, as such each time i need to run this script it takes 7minutes to execute. Is there a way to optimize this such that it will be faster even in files with VERY HIGH layer counts? Thanks
Each Photoshop layer is given a unique ID - (generated at creation in numerical order - I think - don't quote me on that) So you can access each layer by the ID instead of layer.getByname. The code below will show you the ID of the currently selected layer. - The upshot being, if you know the ID, you can get by layerID. :)
To select more than one layer at a time: reuse the select_layer_by_ID with layer and true to add to the current selection.
Get layer by ID:
// Switch off any dialog boxes
displayDialogs = DialogModes.NO; // OFF
var srcDoc = app.activeDocument;
var theLayer = srcDoc.activeLayer;
var myLayerID = get_layer_id(theLayer);
srcDoc.activeLayer = srcDoc.layers[0]; //top layer
// now go back to original layer via layer ID!
// select by layer ID
select_layer_by_ID(myLayerID);
alert("Layer ID: " + myLayerID + "\n" + srcDoc.activeLayer.name);
// Switch off any dialog boxes
displayDialogs = DialogModes.ALL; // ON
// function SELECT LAYER BY ID(int, boolean)
// --------------------------------------------------------
function select_layer_by_ID(id, add)
{
if (add == undefined) add = false;
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putIdentifier(charIDToTypeID('Lyr '), id);
desc1.putReference(charIDToTypeID('null'), ref1);
if (add) desc1.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelection"));
executeAction(charIDToTypeID('slct'), desc1, DialogModes.NO);
}
// function GET LAYER ID(obj)
// --------------------------------------------------------
function get_layer_id(alayer)
{
return alayer.id;
}
I'm trying to create a script out of 2 working scripts
Goal:
We need a script that will go through all the layers in the current document, find each layer marked in certain color (Red for example), copy the names of only the layers marked in red, then put all names in a text layer one after another (attached example image).
Resources:
I found 2 scripts that each do half of what we need, so how to we put them together?
1) "Select by red" goes through the document and finds how many layers marked in "red" are in the document:
#target photoshop
if (app.documents.length > 0) {
// the file;
var myDocument = app.activeDocument;
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
var theOthers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if not layer group collect values;
if (layerSet != "layerSectionEnd" /*&& layerSet != "layerSectionStart"*/ && isBackground != true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var visible = layerDesc.getBoolean(stringIDToTypeID("visible"));
var theColor = layerDesc.getEnumerationValue(stringIDToTypeID("color"));
if (typeIDToStringID(theColor) == "red") {theLayers.push([theName, theID])}
else {theOthers.push([theName, theID])}
};
}
catch (e) {};
};
// if layers are red;
if (theLayers.length > 0) {alert ("there are " + theLayers.length + " Red layers")}
else {alert ("no red layers")}
};
2) "Text box from layer name" takes the name of the currently selected layer, and pastes it into a new text layer called "Comp".
if (app.documents.length > 0) mainScript();
function mainScript() {
try{
var myLayerName = activeDocument.activeLayer.name;
var myLayerText = activeDocument.artLayers.add();
myLayerText.name = "Comp";
myLayerText.kind = LayerKind.TEXT;
var textProperty = myLayerText.textItem;
textProperty.size = 10;
textProperty.font = "Arial";
myLayerText.textItem.contents = myLayerName;
}catch (errStr){
alert(errStr);
}
}
Plan:
From my understanding, we need to start with a loop that's as long as our document size i.e. total number of layers for (var i = 0; i < doc.layers.length; i++).
Then layer by layer the script will check for color ID if (typeIDToStringID(theColor) == "red") . When it finds layer marked in red, it copies the layer name - then either stores it in array (to output later all at once), or creates a new text box and pastes the layer name myLayerText.textItem.contents = myLayerName.
Then for each time it finds another layer marked in red , it copies the layer name, and pastes it in the same text box just a line above/below previous layer name.
Any help is much appreciated!
The only thing you needed to do was to join the names of your theLayers array using the line-break symbol \r:
if (app.documents.length > 0)
{
// the file;
var myDocument = app.activeDocument;
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++)
{
try
{
var ref = new ActionReference();
ref.putIndex(charIDToTypeID("Lyr "), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background")); // if not layer group collect values; if (layerSet != "layerSectionEnd" /*&& layerSet != "layerSectionStart"*/ && isBackground != true)
{
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theColor = layerDesc.getEnumerationValue(stringIDToTypeID("color"));
if (typeIDToStringID(theColor) == "red")
{
theLayers.push(theName); // we only need names here
}
};
}
catch (e)
{};
};
// got our red layers in theLayers
var myLayerText = activeDocument.artLayers.add();
myLayerText.name = "Result";
myLayerText.kind = LayerKind.TEXT;
var textProperty = myLayerText.textItem;
textProperty.size = 10;
textProperty.font = "Arial";
myLayerText.textItem.contents = theLayers.join('\r'); // joining layers with a line-break: this is going to be textItem text
};
Here's the result:
I'd suggest you to take a course on JS on any learning website (code academy, etc): this won't take you more than an hour or two but you'll get the basic concepts: this will make your life much easier in terms of dealing with questions like this.
i'm stuck with a script that detects which layer is visible in a (sub)layerset (aka Group) with the name "Color".
The script below checks for all visible layers and selects them. I can't get it working to do the same thing ONLY in the mentioned layerset.
Any help would be highly appreciated!
#target photoshop
app.bringToFront();
main();
function main(){
if(!documents.length) return;
var Vis = getVisLayers();
deselectLayers();
for(var a in Vis){
selectLayerById(Number(Vis[a]),true);
}
}
function getVisLayers(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
var count = executeActionGet(ref).getInteger(charIDToTypeID('NmbL')) +1;
var Names=[];
try{
activeDocument.backgroundLayer;
var i = 0; }catch(e){ var i = 1; };
for(i;i<count;i++){
if(i == 0) continue;
ref = new ActionReference();
ref.putIndex( charIDToTypeID( 'Lyr ' ), i );
var desc = executeActionGet(ref);
var layerName = desc.getString(charIDToTypeID( 'Nm ' ));
var Id = desc.getInteger(stringIDToTypeID( 'layerID' ));
if(layerName.match(/^<\/Layer group/) ) continue;
var layerType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'layerSection' )));
var isLayerSet =( layerType == 'layerSectionContent') ? false:true;
var vis = desc.getBoolean(charIDToTypeID( "Vsbl" ));
if(!isLayerSet && vis) Names.push(Id);
};
return Names;
};
function selectLayerById(ID, add) {
add = (add == undefined) ? add = false : add;
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID('Lyr '), ID);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID('null'), ref);
if (add) {
desc.putEnumerated(stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelection'));
}
desc.putBoolean(charIDToTypeID('MkVs'), false);
executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
}
function deselectLayers() {
var desc01 = new ActionDescriptor();
var ref01 = new ActionReference();
ref01.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc01.putReference( charIDToTypeID('null'), ref01 );
executeAction( stringIDToTypeID('selectNoLayers'), desc01, DialogModes.NO );
};
enter image description here
Trouble with groups is that you have to jump at the deep end. Sadly the way Photoshop keeps track of it's layers isn't intuitive. The best thing to do is have a recursive function and look over ALL the layers - from that you'll be able to determine if it's a group or not. And then work out if it's visible.
var allLayers = new Array();
var theLayers = collectAllLayers(app.activeDocument, 0);
// function collect all layers
function collectAllLayers (theParent, level)
{
for (var m = theParent.layers.length - 1; m >= 0; m--)
{
var theLayer = theParent.layers[m];
if (theLayer.typename == "ArtLayer")
{
// find the art layers
if (theLayer.visible == true)
{
//do stuff here
}
}
else
{
allLayers.push(level + theLayer.name);
collectAllLayers(theLayer, level + 1)
}
}
}
Thanks to #Ghoul Fool i finally managed to get this working. I changed the code a bit as i only need to check which layer is visible and store this name as a variable. Would be great if someone more skilled could correct my code for others who will use it or parts of it.
Thanks again
// Checking which layer is visible in layeset (group) "Colors" in "Mockup.psd" aka mockupDoc and store it's name for later use in the "save" part.
var front = mockupDoc.layerSets.getByName("Front");
var colors = front.layerSets.getByName("Colors");
for (var m = colors.layers.length - 1; m >= 0; m--)
{
var theLayer = colors.layers[m];
if (theLayer.typename == "ArtLayer")
{
if (theLayer.visible == true)
{
// Sets a variable for the name of the visible Layer in the "Colors" Group, so i can use it later as a part of the Filename when saving.
var activeColor = theLayer.name;
}
}
};
Hey all so I have this script that converts EPS files to Tiffs in Photoshop.
At present it allows you to pick a folder of files to be converted and creates a new folder in that for the Tiff files. I had tried creating the Tiffs in the same folder without creating an extra folder but this seemed to mess with the original EPS file. The conversion was happening fine but it was taking the data out of the EPS and saving it like a blank file. Since I put the new converted Tiff files in a folder it is creating a copy of the original EPS in there too which I don't need.
Basically I need to convert all the EPS files in a folder to Tiffs but do not want to mess with the original EPS and do not want an additional copies of the file.
The script I have at present is as follows:
#include "~/AppData/Local/wbmUtils/lib/underscore.js";
//-------------- declare measurement in pixels and declare vars for HxW --------------\\
app.preferences.rulerUnits = Units.PIXELS;
var height =0;
var width = 0;
//-------------- select input and output folders --------------\\
alert("Choose a folder of EPS's");
var inPath = Folder.selectDialog();
var outPath = inPath+'/Tiffs';
$.writeln(inPath);
$.writeln(outPath);
//-------------- get full image list from input folder --------------\\
var inputs = getImageList (inPath);
function getImageList (dirPath)
{
var contents = dirPath.getFiles();
var imageList=[];
_.each(contents, function(item)
{
imageList.push(item.toString());
})
return imageList;
}
//-------------- create new folder for files --------------\\
$.writeln(inputs);
var imageFolderName = outPath;
var imageFolder = Folder(imageFolderName);
if(!imageFolder.exists) imageFolder.create();
_.each(inputs, function(input)
{
$.writeln("height: " + height + " width: " + width);
var imgWithExt = _.last(input.split('/'))
doPreviews(input, imageFolderName +'/' + imgWithExt);
var of = new File(input);
of.copy (imageFolderName +'/' + imgWithExt.split('.')[0] + '.eps');
})
//-------------- main conversion function --------------\\
function doPreviews(input, output)
{
var idOpn = charIDToTypeID("Opn ");
var desc4 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
desc4.putPath(idnull, new File(input));
var idAs = charIDToTypeID("As ");
var desc5 = new ActionDescriptor();
var idRslt = charIDToTypeID("Rslt");
var idRsl = charIDToTypeID("#Rsl");
desc5.putUnitDouble(idRslt, idRsl, 300.000000);
var idAntA = charIDToTypeID("AntA");
desc5.putBoolean(idAntA, true);
var idEPSG = charIDToTypeID("EPSG");
desc4.putObject(idAs, idEPSG, desc5);
executeAction(idOpn, desc4, DialogModes.NO);
var idMk = charIDToTypeID("Mk ");
var desc7 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
var ref1 = new ActionReference();
var idDcmn = charIDToTypeID("Dcmn");
ref1.putClass(idDcmn);
desc7.putReference(idnull, ref1);
var idUsng = charIDToTypeID("Usng");
var ref2 = new ActionReference();
var idHstS = charIDToTypeID("HstS");
var idCrnH = charIDToTypeID("CrnH");
ref2.putProperty(idHstS, idCrnH);
desc7.putReference(idUsng, ref2);
executeAction(idMk, desc7, DialogModes.NO);
height = app.activeDocument.height;
width = app.activeDocument.width;
if (height > width)
{
$.writeln("IS HIGHER THAN WIDE");
var idImgS = charIDToTypeID("ImgS");
var desc8 = new ActionDescriptor();
var idHght = charIDToTypeID("Hght");
var idPxl = charIDToTypeID("#Pxl");
desc8.putUnitDouble(idHght, idPxl, 6500.000000);
var idscaleStyles = stringIDToTypeID("scaleStyles");
desc8.putBoolean(idscaleStyles, true);
var idCnsP = charIDToTypeID("CnsP");
desc8.putBoolean(idCnsP, true);
var idIntr = charIDToTypeID("Intr");
var idIntp = charIDToTypeID("Intp");
var idautomaticInterpolation = stringIDToTypeID("automaticInterpolation");
desc8.putEnumerated(idIntr, idIntp, idautomaticInterpolation);
executeAction(idImgS, desc8, DialogModes.NO);
} else {
$.writeln("IS WIDER THAN HIGH");
var idImgS = charIDToTypeID("ImgS");
var desc32 = new ActionDescriptor();
var idWdth = charIDToTypeID("Wdth");
var idPxl = charIDToTypeID("#Pxl");
desc32.putUnitDouble(idWdth, idPxl, 6500.000000);
var idscaleStyles = stringIDToTypeID("scaleStyles");
desc32.putBoolean(idscaleStyles, true);
var idCnsP = charIDToTypeID("CnsP");
desc32.putBoolean(idCnsP, true);
var idIntr = charIDToTypeID("Intr");
var idIntp = charIDToTypeID("Intp");
var idautomaticInterpolation = stringIDToTypeID("automaticInterpolation");
desc32.putEnumerated(idIntr, idIntp, idautomaticInterpolation);
executeAction(idImgS, desc32, DialogModes.NO);
}
var idMk = charIDToTypeID("Mk ");
var desc20 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
var ref4 = new ActionReference();
var idDcmn = charIDToTypeID("Dcmn");
ref4.putClass(idDcmn);
desc20.putReference(idnull, ref4);
var idUsng = charIDToTypeID("Usng");
var ref5 = new ActionReference();
var idHstS = charIDToTypeID("HstS");
var idCrnH = charIDToTypeID("CrnH");
ref5.putProperty(idHstS, idCrnH);
desc20.putReference(idUsng, ref5);
executeAction(idMk, desc20, DialogModes.NO);
var idCls = charIDToType("Cls ");
executeAction(idCls, desc20, DialogModes.NO);
//-------------- tiff options --------------\\
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.byteOrder = ByteOrder.MACOS;
tiffSaveOptions.layers = false;
tiffSaveOptions.transparency = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.embedColorProfile = false;
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
tiffSaveOptions.saveImagePyramid = false;
app.activeDocument.saveAs(File(output.split('.')[0]+'.tiff'), tiffSaveOptions, true);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
//-------------- success message --------------\\
alert("ALL DONE!")
I would be inclined to do this with ImageMagick which is installed on most Linux distros and is available for OSX and Windows.
So, at the command-line in your Terminal:
mkdir TIFFs # Make the output directory called "TIFFs"
mogrify -format tif -path TIFFs *.eps # Convert all EPS to TIFFs/*.tif
My script collects data from a Google Form. And puts it into a Spreadsheet. Based on the info in the spreadsheet it should add Calendar events. When the user chose 1 of 2 countrys in the form i would like the script to execute the function for that country.
Norway is one value
Sweden is one value
For example if the value in var country2 = country1.getValue(); is "Sweden" i would like it to only execute the function sweButik(){ Is it possible, and how do i do it?
function getData() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var lastCell = sheet.getRange(lastRow, lastColumn);
var time1 = sheet.getRange(lastRow, 3);
var name1 = sheet.getRange(lastRow, 4);
var info1 = sheet.getRange(lastRow, 5);
var country1 = sheet.getRange(lastRow, 6);
var time2 = time1.getValue();
var name2 = name1.getValue();
var info2 = info1.getValue();
var country2 = country1.getValue();
}
//////////////////////////
function sweButik(){
var sweButik1 = CalendarApp.getCalendarById('company.com_7gvpuutc6h1d7kk5mjb2s5f4ds#group.calendar.google.com').createEvent(name2,
new Date(time2),
new Date(time2), {description: info2});
var sweButik2 = CalendarApp.getCalendarById('company.com_bertj0lfja45425ran8mmrpgc8#group.calendar.google.com').createEvent(name2,
new Date(time2),
new Date(time2), {description: info2});
}
/////////////////////////
function norButik(){
var norButik1 = CalendarApp.getCalendarById('company.com_7d88i0ne013r26i172k8fu16j0#group.calendar.google.com').createEvent(name2,
new Date(tid2),
new Date(tid2), {description: info2});
var norButik2 = CalendarApp.getCalendarById('company.com_sb0ddqmj5ql6uu5769u0qfs2go#group.calendar.google.com').createEvent(name2,
new Date(time2),
new Date(time2), {description: info2});
}
Since your values are fixed, you can do something like :
var country2 = country1.getValue();
if (country2 == "Sweden") {
sweButik();
} else if (country2 == "Norway") {
norButik();
}
But you need some parameters to be passed to these functions, so sweButik will become :
function sweButik (name,time,info) {
var sweButik1 = CalendarApp.getCalendarById('company.com_7gvpuutc6h1d7kk5mjb2s5f4ds#group.calendar.google.com').createEvent(name,
new Date(time),
new Date(time), {description: info});
var sweButik2 = CalendarApp.getCalendarById('company.com_bertj0lfja45425ran8mmrpgc8#group.calendar.google.com').createEvent(name,
new Date(time),
new Date(time), {description: info});
}
And its call will be :
sweButik(name2, time2, info2);
Don't forget to do the same for norButik