As of Parted 3.* the accepted answer is no longer true.
Parted is primarily designed to be used in interactive mode where a human will provide information to parted and answer its questions in real-time.
There is also an option to run parted in script-mode parted -s where commands can be fed to parted all in one go without having to interact step by step with parted.
As of Parted 3.* if the aim is to shrink a partition in script-mode parted will prompt for user intervention and then exit. This is intentional, for safety purposes, according to feedback in this bug report which also provides a patch that works around that limitation.
Parted has an undocumented feature ---pretend-input-tty that behaves like script-mode as it also allows for parameters to be fed to it, all together, except it runs parted in interactive mode.
In this code snippet a disk with one partition is mounted at /dev/loop0 and parted will increase and shrink the size of a partition without objection:
echo -e "resizepart 1 46280703s\nyes\nunit s\nprint\nquit" | sudo parted /dev/loop0 ---pretend-input-tty
The expect command could also be used to automate providing information and answers to parted when it is running in interactive mode.
This script creates a 100MiB disk image file, creates one partition and formats it as ext4.
#!/bin/bash
#
# Script to make a disk image file
#
Create a 100MiB disk file, when partitioned it will have 204800 sectors
cd ~
dd if=/dev/zero of=disk.img bs=1M count=100
loopdevice=$(losetup --show --find --partscan disk.img)
echo $loopdevice
echo $loopdevice"p1"
parted -s $loopdevice mklabel gpt
parted -s $loopdevice mkpart primary ext4 2048s 100%
mkfs -t ext4 $loopdevice"p1"
Now running this next script will call parted and use expect to feed in answers to increase or decrease that partition without problem:
#!/usr/bin/expect
#
# Script that uses the 'expect' command to feed answers to 'parted' command
# when it is running in interactive mode.
#
spawn sudo parted disk.img
expect "(parted)" {send "p\n"}
expect "(parted)" {send "resizepart 1 150000s\n"}
expect "Yes/No?" {send "y\n"}
expect "(parted)" {send "p\n"}
expect "(parted)" {send "q\n"}