-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforLockscreen.c
62 lines (52 loc) · 1.59 KB
/
forLockscreen.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define MAX_BUFFER_SIZE 256
int main()
{
char buffer[MAX_BUFFER_SIZE] ;
char *essid = NULL ;
FILE *fp = popen("iw dev | awk '$1 == \"ssid\"{print $2}'", "r") ;
if (fp == NULL)
{
perror("popen") ;
exit(EXIT_FAILURE) ;
}
if (fgets(buffer, sizeof(buffer), fp) != NULL)
{
// Remove trailing newline character, if present
size_t len = strlen(buffer) ;
if (len > 0 && buffer[len - 1] == '\n')
{
buffer[len - 1] = '\0' ;
}
essid = strdup(buffer) ;
}
pclose(fp) ;
if (essid != NULL)
{
printf("Connected to Wi-Fi network: %s\n", essid) ;
if (strcmp(essid, "LAPTOP-S") == 0)
{
// Run the specified command if ESSID is "LAPTOP-S"
printf("ESSID is LAPTOP-S. Running the specified command.\n") ;
// system("feh --recursive --bg-fill --randomize /home/yash/walls/") ;
system("betterlockscreen -u /home/yash/walls/") ;
}
else
{
printf("ESSID is not LAPTOP-S. Running the specified command.\n") ;
// system("feh --recursive --bg-fill --randomize /home/yash/walls/1") ;
system("betterlockscreen -u /home/yash/walls/1") ;
}
free(essid) ;
}
else
{
printf("Not connected to a Wi-Fi network.\n") ;
// system("feh --recursive --bg-fill --randomize /home/yash/walls/1") ;
system("betterlockscreen -u /home/yash/walls/1") ;
}
return 0 ;
}