@Override
    public void run() throws Exception {		
			
		if (currentAddress == null) {
			println("No Location.");
		    return;
		}
		MemoryBlock memoryBlock = currentProgram.getMemory().getBlock(currentAddress);
		if(!memoryBlock.isInitialized()){
			println("Script cannot run in uninitialized memory.");
			return;
		}
		Listing listing = currentProgram.getListing();
		

		Address currentAddr = currentAddress;        
		
		boolean isInitializedBlock = memoryBlock.isInitialized();
		if(isInitializedBlock){
			currentAddr = memoryBlock.getEnd();
			println("end of byte addr is " + currentAddr);
			byte repeatingByte = currentProgram.getMemory().getByte(currentAddr);
			
		
			MemoryBlock currentMemoryBlock = null;		
		
			
			// search for next repeatedByte from the end of memory
			// until it hits defined area or different byte		
						
			byte prevByte = repeatingByte;
			int repeatLen = 0;
			boolean noCollisions = listing.isUndefined(currentAddr,currentAddr);
			boolean hasLabels = currentProgram.getSymbolTable().hasSymbol(currentAddr);
			println("no collisions at end = " + noCollisions);
			currentMemoryBlock = currentProgram.getMemory().getBlock(currentAddr);
			while((prevByte == repeatingByte) && (noCollisions) && (currentMemoryBlock.equals(memoryBlock)) && (!hasLabels)){
				repeatLen++;
				currentAddr = currentAddr.addNoWrap(-1);
				prevByte = currentProgram.getMemory().getByte(currentAddr);
				noCollisions = listing.isUndefined(currentAddr,currentAddr);
				hasLabels = currentProgram.getSymbolTable().hasSymbol(currentAddr);
				currentMemoryBlock = currentProgram.getMemory().getBlock(currentAddr);					
			}
			if(repeatLen > 0){
			// this takes care of the last one tested that failed
			currentAddr = currentAddr.addNoWrap(1);												
			listing.createData(currentAddr, new AlignmentDataType(), repeatLen);				
			
			println("Applied Alignment datatype at " + currentAddr.toString());												
			 
			}
			else{
				println("No repeating bytes OR data already defined at end of " + memoryBlock);
			}
		}
		else{
			println("Cannot condense uninitialized memory.");
		}		
	}
Script to condense all undefined repeating bytes (ie all 0's or ff's) at the end of the current
memory block
Ghidra/Features/Base/ghidra_scripts/CondenseRepeatingBytesAtEndOfMemory.java