This series is written by a representative of the latter group, which is comprised mostly of what might be called "productivity users" (perhaps "tinkerly productivity users?"). Though my lack of training precludes me from writing code or improving anyone else's, I can, nonetheless, try and figure out creative ways of utilizing open source programs. And again, because of my lack of expertise, though I may be capable of deploying open source programs in creative ways, my modest technical acumen hinders me from utilizing those programs in what may be the most optimal ways. The open-source character, then, of this series, consists in my presentation to the community of open source users and programmers of my own crude and halting attempts at accomplishing computing tasks, in the hope that those who are more knowledgeable than me can offer advice, alternatives, and corrections. The desired end result is the discovery, through a communal process, of optimal and/or alternate ways of accomplishing the sorts of tasks that I and other open source productivity users need to perform.
Showing posts with label xclip. Show all posts
Showing posts with label xclip. Show all posts

Thursday, August 7, 2025

The AI revolution?

That's kind of a dramatic title, but an appropriate one for this blog and this post. I've recently discovered (yes, I've been living under a bit of a rock) AI and its possibilities for the kinds of tech projects I undertake. It turns out that, by using AI, my laborious process of trawling the internet for snippets of information related to the kinds of things I try to do with my computer may have come to an end. Yes, having AI at my disposal, I can have an always-available interlocutor to consult with on these topics, and one who is far more knowledgeable than me about computer coding.

The impact of this on this blog is that I will likely now be, instead of documenting my halting attempts and offering links to articles I've found, the posting of a lot of articles henceforth about scripts AI has helped me to create and related knowledge it has conveyed. I've already developed several scripts over the last few weeks and I keep thinking up more. In fact this post is being published partly by a script AI helped me to develop. True, its initial attempts at using the blogger API turned out to be a huge and fruitless time sink. I finally told it I was calling it quits after many hours of meeting one frustration after another--not necessarily totally the fault of AI, but due in large part to google's inhumanly complex way of expecting users to interface which seem calculated to deviously thwart the standard end user at every turn.

But I managed to get AI to help me develop a semi-automated way of posting using the method discussed in the last post I made here that involves using the xclip utility. In other words, I need to sometimes come to AI's rescue, paltry as my abilities are in this realm. And I've had to several times make suggestions to AI about how to do something or about some utility to use. In fact, I just had a frustrating session with AI trying to develop a working .asoundrc (yes, no pulse or pipewire here, just good old-fashioned alsa) that would allow me to send sound through my laptop's HDMI port. To offer a bit of gory detail, AI couldn't figure out (nor could I) why aplay could send sound via plughw while trying to configure .asoundrc with plughw devices would report that the relevant library couldn't be found.

But AI did provide me with a nice workaround for sending my laptop display out the HDMI port using xrandr, that solution leaving it to the video player (mpv in this case) to select the proper audio device for the sound. In fact, here's a nice bash script I asked it to develop for when I want to send the display through the HDMI port:


#!/bin/bash

# Find the names of your displays with 'xrandr'
# For a typical laptop, this is a good guess:
LAPTOP_DISPLAY="LVDS1"
EXTERNAL_DISPLAY="HDMI1"

# Present the menu
echo "Choose a display configuration (for mpv audio hit g-d keys & select alsa/hdmi once mpv has been started):"
echo "1) Extend desktop (external right of laptop)"
echo "2) Mirror displays"
echo "3) External display only"
echo "4) Revert to laptop display only"
echo -n "Enter your choice (1-4): "
read choice

# Execute the command based on user choice
case $choice in
    1)
        echo "Extending desktop..."
        xrandr --output "$EXTERNAL_DISPLAY" --auto --right-of "$LAPTOP_DISPLAY"
        ;;
    2)
        echo "Mirroring displays..."
        xrandr --output "$EXTERNAL_DISPLAY" --auto --same-as "$LAPTOP_DISPLAY"
        ;;
    3)
        echo "Using external display only..."
        xrandr --output "$EXTERNAL_DISPLAY" --auto --output "$LAPTOP_DISPLAY" --off
        ;;
    4)
        echo "Reverting to laptop display only..."
        xrandr --output "$EXTERNAL_DISPLAY" --off --output "$LAPTOP_DISPLAY" --auto
        ;;
    *)
        echo "Invalid choice. Please enter a number between 1 and 4."
        ;;
esac

By the way, I'm using mostly Google's Gemini so far. I've tried duck.ai as well, which I found to be a bit deficient although, on the positive side they don't seem to do geo-blocking like other services do. I also decided to try a paid service, github's co-pilot. Honestly, I've so far not seen its advantages as compared to Gemini. But I'm still quite new at this, so I may decide in the future to use some better alternative. Time will tell.

I've learned a bit about strategizing to get help from AI as well. I've discovered that I need to develop projects gradually, first coming up with a sort of simplified mock-up of a key part of what I'm aiming to accomplish, then asking it to build gradually on that. Describing to AI a complex project and its aims at the outset is likely to result in AI proposing a complex script, but experience has thus far shown that it will be so unwieldy and with parts so error-prone that it will turn out to be a nightmare to troubleshoot. Better to start off simplistically and build on working parts that can later be tied together.

I would say I stand to learn a lot about coding from AI. It's light years ahead of me when it comes to error-checking routines. I'm usually so focused on getting my tasks accomplished that I don't even think about those sorts of things. But I also suspect that AI doesn't implement sound code practices very well. Some of the scripts it has put together for me, so far as I can tell, have turned out to be horrendously complex monstrosities which, as I think of what they do and how they're designed, seem to me to string together too many routines and files into one. If I understand coding protocols at all correctly, I think these scripts should be divided up in a couple of smaller scripts and the data they produce should be turned into separate files. This is all pretty abstract without giving some concrete examples. But in future posts I should be posting here some of that code, which may give a clearer indication of what I think I'm getting at.

So stay tuned for those posts.

Monday, October 21, 2024

xclip to the rescue? How I wish . . .

I find the blogging platform I've been using for this blog to be horrendous. First, I don't want to have to log into a website to write articles: I'd rather type them on my computer, usually using my favored command-line text editor nano.

I was iniatially enthused to discover that blogspot/blogger (the host for this blog) offered the possibility of e-mailing posts. Esssentially, you add a custom word to an e-mail address they provide, and you can use that to send posts directly to your blog (subject line becomes the blog posting's title). Great, I thought, I can type posts on my computer and send them to my blog.

But my enthusiasm was shortlived. Initial tests indicated that the blogging platform was inserting a bunch of extraneous html tags into postings I'd send like that. No problem, I thought, I'll just write my posts with html, tags pre-inserted. Tests using that method indicated that the platform was continuing to insert those extraneous tags. See the graphic below for an indication of how the file looks in html editing view on blogger's site (all the &gt &lt &#39 and <br> were added by their system, not by me):


So I was left with a dilemma: how can I more conveniently, according to my preferred practices, continue blogging here? Researching the matter revealed the xclip utility, which appeared to be a good workaround for helping deal with the constraints involved in continuing to blog on this platform.

I discovered that, after I save the posting I've written under nano, I can simply cat the file into the system's clipboard by running a command like cat myfile.txt | xclip (see the LATER EDIT note added at the very end of this post for the corrected invocation for the blogger site) and from there paste it into the platform's editor interface by placing my cursor there and clicking the middle mouse button. Granted, it's pretty much the same as using a graphical text editor like leafpad and hitting ctrl-a to highlight the whole of the file, ctrl-c to copy the highlighted text to the clipboard, then ctrl-v after placing the cursor into the platform's editor interface. Not ideal, since I would much prefer if the e-mailing method would work as I had hoped by just importing the text as written in the file, but it's an acceptable (at least for now) workaround.

Perhaps more to come later, if I manage to make improvements or to figure out some heretofore overlooked factor.

Afterthought: I tried to paste this post into the blogger editing interface using xclip and it didn't work. Nothing would paste. So I had to paste the text into leafpad, then do the ctrl-a, ctrl-c, ctrl-v trick to be able to paste it here. So I changed the exclamation sign I had initially placed at the end of the title to a question mark, since it may not provide the solution after all. Sigh.

LATER EDIT: IMPORTANT! I've discovered that the way I can paste text into blogger using xclip is by running it with a couple of switches, as follows: cat myfile.txt | xclip -selection clipboard: having done that, I can then place the cursor in blogger's html editor and hit ctrl-v and the text from the file will paste into the editor as intended.