﻿//Hello! This script moves every selected object left by a little more than the page width.

var document = app.activeDocument.documentPreferences;
var docWidth = document.pageWidth;
var magicNumber = (docWidth / 100) * magicNumber;

var selection = app.selection;
var page = app.activeWindow.activePage;

try {
	var selection = app.selection;
	for (i = 0; i < selection.length; i++){
	
		var selectedObject = app.selection[i];
		app.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;  
		app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;  
		app.activeDocument.zeroPoint = [0,0]; 
		
		if ('graphics' in selectedObject && selectedObject.graphics.count() > 0){
			var graphic = selectedObject.graphics[0];
			var imageBool = true;
		} else {
			var imageBool = false;
		}
		 
		
		var startPosX = selectedObject.geometricBounds[1] - (docWidth + 10);
	    var endPosX = selectedObject.geometricBounds[3] - (docWidth + 10);

    	var startPosY = selectedObject.geometricBounds[0];
	    var endPosY = selectedObject.geometricBounds[2];

		selectedObject.geometricBounds = [startPosY, startPosX, endPosY, endPosX];
		
		if (imageBool){
			var imgStartPosX = selectedObject.graphics[0].geometricBounds[1] - (docWidth + 10);
	    	var imgEndPosX = selectedObject.graphics[0].geometricBounds[3] - (docWidth + 10);

	    	var imgStartPosY = selectedObject.graphics[0].geometricBounds[0];
		    var imgEndPosY = selectedObject.graphics[0].geometricBounds[2];
		    
		    selectedObject.graphics[0].geometricBounds = [imgStartPosY, imgStartPosX, imgEndPosY, imgEndPosX];
		}

	}

} catch (e) {
	alert("This didn't work.");
}