Is it possible to disable autocorrect on the simulator via a script?

1,553 views
Skip to first unread message

Niels Frydenholm

unread,
Sep 7, 2013, 4:22:22 PM9/7/13
to calaba...@googlegroups.com
Hi

I am refactoring some old tests, which also means using keyboard_enter_text instead of set_text.
But that has brought a new problem with autocorrect and the other spelling changes that iOS is so nice to do by default.


Is there a way to disable auto-correct with some ios-simulator launch options, so my tests won't break after a simulator-reset?

Krukow

unread,
Sep 7, 2013, 5:38:25 PM9/7/13
to calaba...@googlegroups.com
I've not tried doing this. However, as many things with simulator settings this is often a .plist controlling it.

Try looking at e.g.

~/Library/Application Support/iPhone Simulator/*.*/Library/Preferences

etc.

Niels Frydenholm

unread,
Sep 8, 2013, 2:21:49 PM9/8/13
to calaba...@googlegroups.com
That was a good place to look :-)

In case anyone else could use it one day, this will change those settings


sim_sdk_version=6.1

defaults write ~/Library/Application\ Support/iPhone\ Simulator/$sim_sdk_version/Library/Preferences/com.apple.Preferences.plist KeyboardAutocapitalization -bool NO

defaults write ~/Library/Application\ Support/iPhone\ Simulator/$sim_sdk_version/Library/Preferences/com.apple.Preferences.plist KeyboardAutocorrection -bool NO

defaults write ~/Library/Application\ Support/iPhone\ Simulator/$sim_sdk_version/Library/Preferences/com.apple.Preferences.plist KeyboardCheckSpelling -bool NO

I've just put it in a "run script build phase", and it works fine on my local machine (I'll find out tomorrow if it works on the CI environment, too).
There might be a more sophisticated way to find the sim-version the app will be installed on, but this works for now :-)

Krukow

unread,
Sep 9, 2013, 6:43:17 AM9/9/13
to calaba...@googlegroups.com
Thanks for sharing!

engr.a...@gmail.com

unread,
Aug 21, 2014, 10:44:30 AM8/21/14
to calaba...@googlegroups.com
Hi,

It did not work for me. I went to the directory, opened the plist files and set the booliean = No. but no success. 

ginger

unread,
Aug 21, 2014, 2:51:54 PM8/21/14
to calaba...@googlegroups.com
The method should work, but the keys are probably wrong. 

They should be KeyboardsAutocapitalization, KeyboardsAutocorrection, KeyboardsCheckSpelling.

And actually you can also change the keyboard preference from settings :)

Niels Frydenholm

unread,
Aug 21, 2014, 3:58:41 PM8/21/14
to calaba...@googlegroups.com
After you manually changed (or added) the values in the plist, try to close your app completely and start it again, to see if the changes will work. As far as I remember you'll have to make the changes before starting the app (or restart it after the changes).

Niels Frydenholm

unread,
Oct 17, 2014, 11:06:04 AM10/17/14
to calaba...@googlegroups.com
I am trying to make this feature (to change certain preferences) work again with Xcode 6. Apple has changed the location of the simulators, but I *think* I'm on the right track for a solution.

I'm using the new xcrun simctl to get a list of all devices, and then I change my wanted settings like this

defaults write ~/Library/Developer/CoreSimulator/Devices/$sim_uuid/data/Library/Preferences/com.apple.Preferences.plist KeyboardAutocapitalization -bool NO

with $sim_uuid being the weird secret name :-)

I do change the plist file, but it seems that everytime I start a test/simulator, everything in that folder is replaced - so my settings are overwritten :-/

Any ideas where I should change the com.apple.Preferences.plist file? - I would like to change real source that is being copied into the above folder when the simulator/test starts :-)

Niels Frydenholm

unread,
Oct 20, 2014, 5:06:58 AM10/20/14
to calaba...@googlegroups.com
It looks like com.apple.Preferences.plist is overwritten when I use the setting "RESET_BETWEEN_SCENARIOS' = '1'

We are moving towards getting rid of that setting (so we can execute faster in the Cloud, without doing install/uninstall all the time), but we are not there yet, so I would like to still do this for a while.

Prior to iOS 8, I believe the RESET_BETWEEN_SCENARIOS only influenced the data for my app (e.g. the documents folder), but now it also influences my simulator settings like preferences.
Is there a "hook" when the reset is done, or maybe a way to specify files not to delete during the reset (maybe being able to specify if reset should do both data and simulator settings, or only data), so I can keep my preferences until I really reset the simulator? :-)

/Niels

Joshua Moody

unread,
Oct 23, 2014, 11:03:14 PM10/23/14
to calaba...@googlegroups.com
Hey Niels,

Prior to iOS 8, I believe the RESET_BETWEEN_SCENARIOS only influenced the data for my app

You are correct.

The details of the current implementation can be found here:


TLDR; We can't find the application sandbox in CoreSimulator.

Would you be willing to share your preferences code with us?  We might be able to add it to calabash as a built-in method that can be called before the application is launched and after the $ xcrun simctl erase call is made.

Niels Frydenholm

unread,
Oct 24, 2014, 3:23:22 PM10/24/14
to calaba...@googlegroups.com
Of course - but there is not much to share :-)

I've made a new shell script where I just tried to set the same settings as I did in the "old simulator style".
So far I've been running that script as the last part of the "Build phase" for the calabash-target - only setting it for the sdk we were currently on.
But now with the CoreSimulator style, it weren't as simple - and as you can see I just went for a solution that sets the same preferences for all simulators. 

The new script works - until the reset-between-scenarios resets the simulator :-)

#!/bin/bash

prepareSimulators(){
xcrun simctl list devices | grep -v '^[-=]' | cut -d "(" -f2 | cut -d ")" -f1 | while read -r line ; do
setPreferencesInSimulator $line
done

}

setPreferencesInSimulator(){
    sim_uuid=$1
    echo "Setting simulator pref in $sim_uuid"
    defaults write ~/Library/Developer/CoreSimulator/Devices/$sim_uuid/data/Library/Preferences/com.apple.Preferences.plist KeyboardAutocapitalization -bool NO
    defaults write ~/Library/Developer/CoreSimulator/Devices/$sim_uuid/data/Library/Preferences/com.apple.Preferences.plist KeyboardAutocorrection -bool NO
    defaults write ~/Library/Developer/CoreSimulator/Devices/$sim_uuid/data/Library/Preferences/com.apple.Preferences.plist KeyboardCheckSpelling -bool NO
}

prepareSimulators


> We might be able to add it to calabash as a built-in method that can be called before the application is launched and after the $ xcrun simctl erase call is made.
As a method to override in the hooks.rb (or somewhere else)?

On a (little) different note, I also need to find out how the simctl addphoto works (should it eg. be invoked before the simulator is started?), so I can convert our current "hack" to copy images to the right simulator folder with the new official way of adding photos.

/Niels

f.a.b White

unread,
Feb 16, 2015, 3:49:52 AM2/16/15
to calaba...@googlegroups.com
Hey Josh,

> We might be able to add it to calabash as a built-in method that can be called before the application is launched and after the $ xcrun simctl erase call is made.

ist this still a thing?

Best,
Fabian

f.a.b White

unread,
Feb 16, 2015, 3:57:40 AM2/16/15
to calaba...@googlegroups.com
Just saw the according issue on GitHub: https://github.com/calabash/run_loop/issues/64

Tester

unread,
Apr 19, 2016, 3:06:06 PM4/19/16
to calabash-ios
My solution was to add this line of code before entering text:

query('UITextField', [{setAutocorrectionType:1}])

Joshua Moody

unread,
Apr 19, 2016, 3:19:07 PM4/19/16
to calabash-ios

Be sure to call that before presenting the keyboard.

jjm

--
You received this message because you are subscribed to the Google Groups "calabash-ios" group.
To unsubscribe from this group and stop receiving emails from it, send an email to calabash-ios...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rodrigo gomez giribaldi

unread,
Sep 22, 2016, 11:51:18 AM9/22/16
to calabash-ios
Just enter letters instead of numbers and you wont have that problem.
Reply all
Reply to author
Forward
0 new messages