setting output analog/digital pin to ground
Yes, setting a pin to OUTPUT and setting it LOW effectively connects the pin to ground (via a few ohms of resistance).

There's a couple of things wrong with your code, though, which you should address:


Use digitalWrite() not analogWrite(). 


analogWrite(pin, 0) is effectively the same as digitalWrite(pin, 0), but it's ambiguous to someone reading your code.


You never "release" the pin, so once it goes LOW it stays LOW.  You should emulate open drain by setting it to INPUT when not using it.
You should get into the habit of putting repeated code into functions to make it more understandable what's going on.


For example:

void setup() {
  Serial.begin(9600);
  pinMode(ds1, INPUT);
  pinMode(d1, INPUT);
  waitForCD();
}

void loop() {
  triggerEject();
  waitForCD();
  delay(1000);
}

void triggerEject() {
  pinMode(d1, OUTPUT);
  digitalWrite(d1, LOW); // Press the button
  delay(100); // This is how long the button is pressed for
  pinMode(d1, INPUT); // Release the button
}

void waitForCD() {
  while(!analogRead(ds1)) //if the CD isn't inside the drive wait
  {}
}



!analogRead(ds1) will only ever be true if the voltage at pin A2 is exactly zero volts. If you really want to read an analog voltage here you should find a threshold value that the value is compared to:

while (analogRead(ds1) &lt; 100)) {}


Or it may be that you actually want to use digitalRead()...