Ejecting iPhone from Finder with Applescript or shell

Hello,

I need to find a way to eject the iPhone (in Big Sur) via a script or a shell command.

The reason is that when I turn off my Mac, very often prevents me from doing it because it is synchronizing the iPhone, and I would like to interrupt synchronization, which can be interrupted only by expelling the iPhone.

In iTunes it was easy to do it, but now the iPhone is managed by the Finder, so I don't know how to do it,

Some solutions?

Mac mini, macOS 11.4

Posted on Jun 9, 2021 7:47 AM

Reply
Question marked as Top-ranking reply

Posted on Jul 8, 2021 2:46 AM

My AppleScript skills are pretty rusty, but if not opposed to using a GUI script you could try:


tell application "Finder"
	activate
	if (count windows) is 0 then make new Finder window
end tell
delay 3
tell application "System Events"
	tell process "Finder"
		try
			--change the row number below for your situation
			click button "Eject" of UI element 1 of row 18 of outline 1 of scroll area 1 of splitter group 1 of window 1
		end try
	end tell
end tell
delay 3
tell application "Finder"
	close window 1
end tell


The script assumes the Finder sidebar items you've chosen to show are static. To get the row number to use in the script, with iPhone attached, count the rows of text, including sidebar headings (e.g., Favorites, iCloud, and Locations), from the top to the row with iPhone. The delays are there so you can see if the script is working. You might try the script with reduced delays or eliminate them altogether. The row the iPhone shows up in Finder's sidebar when connected should (maybe?) be consistent. At least it is on my Mac.

6 replies
Question marked as Top-ranking reply

Jul 8, 2021 2:46 AM in response to pauclaude

My AppleScript skills are pretty rusty, but if not opposed to using a GUI script you could try:


tell application "Finder"
	activate
	if (count windows) is 0 then make new Finder window
end tell
delay 3
tell application "System Events"
	tell process "Finder"
		try
			--change the row number below for your situation
			click button "Eject" of UI element 1 of row 18 of outline 1 of scroll area 1 of splitter group 1 of window 1
		end try
	end tell
end tell
delay 3
tell application "Finder"
	close window 1
end tell


The script assumes the Finder sidebar items you've chosen to show are static. To get the row number to use in the script, with iPhone attached, count the rows of text, including sidebar headings (e.g., Favorites, iCloud, and Locations), from the top to the row with iPhone. The delays are there so you can see if the script is working. You might try the script with reduced delays or eliminate them altogether. The row the iPhone shows up in Finder's sidebar when connected should (maybe?) be consistent. At least it is on my Mac.

Jun 12, 2021 10:29 AM in response to pauclaude

pauclaude wrote:

Hello,
I need to find a way to eject the iPhone (in Big Sur) via a script or a shell command.
The reason is that when I turn off my Mac, very often prevents me from doing it because it is synchronizing the iPhone, and I would like to interrupt synchronization, which can be interrupted only by expelling the iPhone.
In iTunes it was easy to do it, but now the iPhone is managed by the Finder, so I don't know how to do it,
Some solutions?


You can eject the iphone directly from Finder like any other external drive

Use the Finder to sync your iPhone, iPad, or iPod with your ...


Finder>Sidebar>Locations> iOS device







Jul 12, 2021 1:24 AM in response to Roote

Thank you, Roote!


Very good script. In fact I don't even have to count the lines visually, I just need my script to find the volume to be ejected directly with the name taken from the list of the elements.


get name of UI element of every row of outline 1 of scroll area 1 of splitter group 1 of window 1 of process "Finder"


The problem is that the element is selected but the relative window is not opened (the ideal would be in a new tab), then the command gives error.


--> error number -1728 from button "Eject" of UI element 1 of row 25 of outline 1 of scroll area 1 of splitter group 1 of window 1 of process "Finder"


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Ejecting iPhone from Finder with Applescript or shell

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.