focusedWindow = spawn ("notify-send \"Focused on " <> readWindowName ++ "\"")
readWindowName :: String
readWindowName = let wn = runProcessWithInput "xdotool" ["getactivewindow getwindowname"] "" in wn
I'm trying to get the output of the process xdotool
using the function runProcessWithInput, but the resulting error pops up:
xmonad.hs:236:121: error:
• Couldn't match type ‘[Char]’ with ‘Char’
Expected: String
Actual: [String]
• In the expression: wn
In the expression:
let wn = runProcessWithInput "xdotool" [...] "" in wn
In an equation for ‘readWindowName’:
readWindowName
= let wn = runProcessWithInput "xdotool" ... "" in wn
|
236 | readWindowName = let wn = runProcessWithInput "xdotool" ["getactivewindow getwindowname"] "" in wn
| ^^
readWindowName
needs to be a String as it is concatenated into a string inside spawn
in focusedWindow
. However, the function returns a [String], which is where I'm stuck at. Tried unlines
, but I can't seem to make it work.
I also tried different methods of the same function, but they also don't work:
readWindowName' :: String
readWindowName' = do
wn <- runProcessWithInput "xdotool" ["getactivewindow getwindowname"] ""
return wn
readWindowName'' :: String
readWindowName'' = let wn = runProcessWithInput "xdotool" ["getactivewindow getwindowname"] ""
wn' = unlines wn
in wn'
readWindowName''
gives a different error:
xmonad.hs:236:51: error:
• No instance for (MonadIO [])
arising from a use of ‘runProcessWithInput’
• In the expression:
runProcessWithInput "xdotool" ["getactivewindow getwindowname"] ""
In an equation for ‘wn’:
wn
= runProcessWithInput
"xdotool" ["getactivewindow getwindowname"] ""
In the expression:
let
wn = runProcessWithInput "xdotool" [...] ""
wn' = unlines wn
in wn'
|
236 | readWindowName = let wn = runProcessWithInput "xdotool" ["getactivewindow getwindowname"] ""
|
I did research about many others' exact problem (namely here, here, and here), and I found that in the source code of runProcessWithInput
, it uses the return
statement, which (I believe) might be the problem in my code, mentioned in this answer:
return :: Monad m => a -> m a
is used to wrap a value (of type a) in a monad.
Is there any way to get around this or a different function that I haven't discovered yet other than editing the runProcessWithInput
source code?
Okay, after some time off this problem, it turns out that the solution was simpler than I thought.
focusedWindow = do
wn <- runProcessWithInput "xdotool" ["getactivewindow", "getwindowname"] ""
spawn ("notify-send 'Focused on " ++ wn ++ "'")