The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
0

status_command and php script

asked 2014-11-13 18:39:39 +0000

anonymous user

Anonymous

Hello. I have this php code to count the unread message from the mailbox

  1 <?php
  2 
  3     $conn   = imap_open('{imap.gmail.com:993/imap/ssl}INBOX', 'test@gmail.com', 'pass', OP_READONLY);
  4 
  5     $msgnos = imap_search($conn, 'UNSEEN');
  6 
  7     $unread = count($msgnos);
  8 
  9     $return = array("full_text"=>$unread, 'name'=>'newmail','color'=>'#FF0000');
 10 
 11     echo json_encode($return);
 12 
 13 
 14 ?>

the status command in .i3/config file

165 bar {
166         status_command i3status | php /home/trap/bin/mailcheck/mailck.php
167 }

The problem is that Error: status_command process exited unexpectedly (exit 0)

Why that's happening ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-11-14 14:17:26 +0000

Adaephon gravatar image

i3bar expects status_command to keep running and produce output line by line.

The reason it fails in your case is that you are using an output redirection | to pass the output of i3status to php /home/trap/bin/mailcheck/mailck.php, but the php script is not actually waiting for input and just exits (with status 0) after printing its output just once.

What you would have to do to get this to work is something like this with your PHP script (I do not know enough PHP to actually write the code for you):

  1. establish IMAP connection (line 3 of your original code)
  2. read input from STDIN line by line
  3. for each line of input
    1. run line 5-9 of your original script
    2. decode json from line to array
    3. append $return to the array
    4. encode the array to json
    5. echo the json

Ensure that the output_format set in the i3status configuration is i3bar else step 3.2 may fail.

If the connection to the IMAP server breaks often it may be necessary to pull step 1. into the loop. In that case it may also be necessary to close the connection after pulling the information.

In the i3status manpage is also an example on how to extend i3status with a shell script.

edit flag offensive delete link more

Comments

I did what you said and now the php script return such data (http://pastebin.com/xxMstfue) but in the status bar everything works properly except from the place where i want to print unread mails. Instead , it writes SPEC VIOLATION (null).

F.N gravatar imageF.N ( 2014-11-14 18:45:20 +0000 )edit

Ok. Fixed it by putting the full_text value in quotes "". Do you know who to transfer that value in the top of the status bar ? Now it is right and i want it to go left. Any idea ?

F.N gravatar imageF.N ( 2014-11-14 19:30:43 +0000 )edit

Do you mean the position of the whole status output in the bar or just the position of mailbox status in relation to the rest of the status message?

Adaephon gravatar imageAdaephon ( 2014-11-15 14:08:38 +0000 )edit

i mean the position of mailbox status in relation to the rest of the status message

F.N gravatar imageF.N ( 2014-11-15 20:47:45 +0000 )edit

Instead of appending `$return` to the array in step 3.3 you need to prepend it. I'm not sure how this is done correctly in PHP. Something like `$array = [$return] + $array`, maybe?

Adaephon gravatar imageAdaephon ( 2014-11-17 10:02:47 +0000 )edit

Question Tools

1 follower

Stats

Asked: 2014-11-13 18:39:39 +0000

Seen: 516 times

Last updated: Nov 14 '14