Question: I am trying to interact with iTunes "Export Library.." dialog.

I tried "set choices to every menu item of menu 1 of pop up button 1 of group 1 of window winName" but it says "group 1" is an invalid index?

Here's the relevant code: (the call parameters are: "iMac-8GB", "iTunes", "iTunes", false"

```
on handleDir(dir, winName, appName, createIt)
    local foundIt, ndx
    set foundIt to false
    if winName is not "" then
        tell application "System Events" to tell process "iTunes"
            set choices to every menu item of menu 1 of pop up button 1 of group 1 of window winName

```

Answer: 
You are requesting the permission with the same request code (here: 1).

Try this:

```
public  boolean isPermissionGranted() {
    if (Build.VERSION.SDK_INT >= 23) {
        if (checkSelfPermission(android.Manifest.permission.READ_PHONE_STATE)
                == PackageManager.PERMISSION_GRANTED) {
            Log.v("TAG","Permission is granted");
            return true;
        } else {

            Log.v("TAG","Permission is revoked");
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_PHONE_STATE}, 2);
            return false;
        }
    }
    else { //permission is automatically granted on sdk<23 upon installation
        Log.v("TAG","Permission is granted");
        return true;
    }
}

 @Override
public void onRequestPermissionsResult(int requestCode,
                                       String permissions[], int[] grantResults) {
    switch (requestCode) {

        case 2: {

            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                Toast.makeText(getApplicationContext(), "Permission granted", Toast.LENGTH_SHORT).show();
                //do your specific task after read phone state granted
            } else {
                Toast.makeText(getApplicationContext(), "Permission denied", Toast.LENGTH_SHORT).show();
            }
            return;
        }

        // other 'case' lines to check for other
        // permissions this app might request
    }
 }

```

Use it like this:

```
if(isPermissionGranted()){
    //do your specific task after read phone state
}

```

Also, in your manifest, add: 

```
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

```
```
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
    {
        if (checkSelfPermission(Manifest.permission.READ_PHONE_STATE)
                != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE},
                    PERMISSIONS_REQUEST_READ_PHONE_STATE);
        }
        else
            {
            mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
                return;
            }
            IMEI_Number_Holder= mTelephonyManager.getDeviceId();
            }
    }
    else
    {
        mTelephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
            return;
        }
        IMEI_Number_Holder = mTelephonyManager.getDeviceId();
    }

```