Sử dụng mã script ngắn này để buộc các ứng dụng khởi động tự động trên macOS mở ở chế độ minimized.

Sử dụng mã nguồn rút gọn này để buộc các mục đăng nhập của macOS mở dưới dạng minimized #Apple #macOS #TechTip #Scripting #Shortcut
Dọn dẹp không gian làm việc trên máy Mac của bạn khi khởi động bằng cách sử dụng quy trình viết script để mở các mục đăng nhập ở chế độ minimized. Tùy chỉnh quy trình bằng cách thêm các ứng dụng ưa thích vào danh sách, đảm bảo tuân thủ tiêu chí đặt tên cần thiết. Thực thi Mã Script Đăng Nhập Chính để đảm bảo mã script chạy tự động sau mỗi lần đăng nhập. Bạn có thể đã nhận thấy rằng các phiên bản sau của macOS thiếu tùy chọn mở các mục đăng nhập ở chế độ minimized, dẫn đến môi trường khởi động một chút rối rắm. Loại bỏ điều đó bằng cách sử dụng lối tắt viết script này. Cách Sử Dụng Lối Tắt Này Sử dụng lối tắt này rất đơn giản. Có một chú thích ở đầu với một cái giải thích vắn tắt về cách sử dụng, nhưng chúng ta hãy đi sâu hơn vào đây, phải không? Bước 1: Tải về Lối Tắt Sử dụng liên kết iCloud này để tải về và thêm quy trình làm việc của Shortcuts vào bộ sưu tập cá nhân của bạn. Sau đó, mở ứng dụng Shortcuts và mở quy trình làm việc bạn vừa thêm. Cứ thoải mái đổi tên Lối Tắt thành bất kỳ cái gì bạn muốn, nhưng cho mục đích của bài hướng dẫn này, chúng ta sẽ sử dụng tên mặc định “Lối tắt mở minimized của Kipps”. Bây giờ, đi tới cài đặt cho Shortcuts, bấm vào tab Advanced, và kích hoạt tùy chọn “Cho phép Chạy Scrip”. Bước 2: Thêm Ứng Dụng Của Bạn Vào Danh Sách Lối Tắt Trong lối tắt bạn đã tải về, bạn sẽ nhận thấy cấu hình mặc định của nó chứa ứng dụng ChatGPT trong danh sách chỉ là một chỗ đặt. Hãy tự do xóa nó và thêm những ứng dụng mà bạn muốn. Hãy nhớ rằng khi bạn thêm một mục vào danh sách, bạn cần làm điều đó đúng cách ứng dụng được viết hoa thường như thế nào. Bạn không cần sử dụng phần mở rộng tệp “.app” Trước khi tiến tới bước tiếp theo, hãy chắc chắn xóa bất kỳ ứng dụng nào bạn đã thêm vào lối tắt này khỏi phần “Mục Đăng Nhập” của Cài Đặt Hệ Thống >Chung. Bước 3: Kiểm Tra lối tắt Nếu những ứng dụng bạn đã thêm hiện đang mở, hãy tắt tất cả chúng (đảm bảo rằng bạn thật sự đã thoát ứng dụng chứ không phải đóng cửa sổ). Sau đó, nhấp vào nút play trong cửa sổ lối tắt của bạn để chạy lối tắt. Đảm bảo rằng tất cả các ứng dụng đã thêm mở ẩn như dự kiến. Nếu vậy, chuyển qua phần tiếp theo. Tạo Một Mã Script Đăng Nhập Chính Bước tiếp theo là sử dụng một chút việc viết script nhẹ để làm cho lối tắt này chạy mỗi lần đăng nhập. Mở Terminal. Nếu bạn chưa có một thư mục được chỉ định cho các script, tôi khuyến nghị tạo một trong thư mục home của bạn với một thư mục con khác dành riêng cho các script shell. Làm như vậy bằng cách thực hiện lệnh Terminal saumkdir -p ~/scripts/shell_scripts Bây giờ bạn đã tạo thư mục script shell của mình, hãy tạo và chỉnh sửa script đăng nhập thực sự của bạn bằng lệnh sau:nano ~/scripts/shell_scripts/my_login_script.sh Sau khi thực hiện lệnh trên, bạn sẽ được chào đón với giao diện chỉnh sửa của nano. Sao chép nội dung sau vào trường văn bản.shortcuts run “Lối tắt mở minimized của Kipps” Chắc chắn thay thế văn bản “Lối tắt mở minimized của Kipps” bằng tên Lối Tắt bạn đã quyết định. Nhấn Command+O, sau đó Enter để lưu những chỉnh sửa bạn vừa thực hiện. Sau đó, bạn có thể thoát khỏi nano bằng cách nhấn Commanf+X. Tiếp theo, bạn cần làm cho script bạn vừa tạo trở nên có thể chạy bằng cách sử dụng lệnh sau.sudo chmod +x ~/scripts/shell_scripts/my_login_script.sh Sau khi thực hiện lệnh, bạn sẽ được yêu cầu nhập mật khẩu của mình. Hãy nhập vào. Voilà, script đăng nhập của bạn bây giờ có thể chạy. Bây giờ, bạn muốn kiểm tra nó bằng cách chạy nó bằng lệnh sau.bin/zsh ~/scripts/shell_scripts/my_login_script.sh Nếu nó chạy thành công, bạn đã sẵn sàng tiến tới phần tiếp theo, đảm bảo rằng script của bạn chạy tự động khi đăng nhập. Chạy Script Khi Đăng Nhập Để kích hoạt chạy script của bạn khi đăng nhập, chúng ta sẽ sửa đổi tập tin .profile của bạn. Nếu bạn chưa bao giờ làm việc với tập tin này trước đó, bạn có thể cần tạo nó. May mắn thay, các lệnh Terminal cho cả để tạo và chỉnh sửa tập tin này là giống nhau:nano ~/.profile Dán nội dung sau vào trường văn bản, thay thế “TÊN_ĐĂNG_NHẬP_CỤC_BỘ_CỦA_BẠN” bằng tên đăng nhập của bạn như nó xuất hiện trong thư mục home của bạn. Mặc định, đây là tên đăng nhập của bạn nhưng không có bất kỳ chữ cái viết hoa nào.USER=”TÊN_ĐĂNG_NHẬP_CỤC_BỘ_CỦA_BẠN”if ( -f /Users/”$USER”/Scripts/Bash\ Scripts/my_login_script.sh ); then /Users/”$USER”/Scripts/Bash\ Scripts/my_login_script.shfi Nhấn Comand+O, theo sau là Enter để lưu tập tin. Sau đó, nhấn Command+X để thoát khỏi nano. Đó là tất cả! Script đăng nhập đã tạo sẽ chạy tự động mỗi khi bạn đăng nhập, điều đó sẽ, lần lượt, chạy lối tắt của chúng ta để mở các mục đăng nhập ở trạng thái minimized. Để kiểm tra cấu hình cuối cùng, đăng xuất hoàn toàn và đăng nhập lại. Hãy nhớ rằng lần chạy đầu tiên của bạn có thể yêu cầu bạn cấp quyền cho script đăng nhập của bạn. Sau khi bạn đã làm, hãy đăng xuất và đăng nhập lại một lần nữa. Với quyền hạn cần thiết được cấp, script đăng nhập của bạn sẽ chạy như ý. Một trong những điểm thu hút cốt lõi của macOS là sự sạch sẽ của giao diện của nó. Sử dụng phương pháp truyền thống để mở ứng dụng khi đăng nhập có thể tạo ra hiệu ứng làm tăng thêm rắn rối và tiếng ồn hình ảnh từ đầu cuộc làm việc của bạn. Bằng cách sử dụng Lối Tắt và quy trình viết script được trình bày ở trên, bạn có thể dễ dàng khôi phục môi trường khởi động sạch sẽ mà không gây ra sự rối rắm nhưng vẫn giữ các ứng dụng khởi động mở và sẵn sàng trong nền.

Nguồn: https://www.howtogeek.com/use-this-script-to-force-macos-login-items-to-open-minimized/

Key Takeaways

  • Clear clutter from your Mac desktop on startup by using a scripting workflow to open Login Items minimized.
  • Customize the workflow by adding preferred apps to the list, making sure to follow the required naming criteria.
  • Execute a Master Login Script to ensure the script runs automatically at every login.


You may have noticed that later versions of macOS lack the option to open Login Items minimized, resulting in a rather cluttered startup environment. Do away with that by using this scripting shortcut.


How to Use This Shortcut

Using this shortcut is very straightforward. There is a comment at the top with an abridged explanation of its use, but let’s get a little deeper into it here, shall we?

Step 1: Download the Shortcut

Use this iCloud link to download and add the Shortcuts workflow to your own personal collection. Then, open the Shortcuts app and open the workflow you just added. Feel free to rename the Shortcut to whatever you want, but for the purpose of this tutorial, we will use the default name “Kipp’s Minimized Login Items Shortcut.”

Adding the minimized login items shortcut.


Now, go to the settings for Shortcuts, click the Advanced tab, and enable the “Allow Running Scripts” option.

Allowing your shortcut to run scripts

Step 2: Add Your Apps to the Shortcut’s List

In the shortcut you downloaded, you’ll notice its default configuration has the ChatGPT app in the list as a placeholder. Feel free to delete it and add whichever ones you want.

Keep in mind that when you add an item to the list, you need to do so exactly how the app is spelled and capitalized. You do not need to use the “.app” file extension

Add your apps to the shortcut list.


Before moving onto the next step, be sure to remove any of the apps you’ve added to this shortcut from the “Login Items” section of System Settings > General.

Step 3: Test the shortcut

If the apps you’ve added are currently open, close all of them (ensure you actually quit the app rather than just close the window).

Then, click the play button in your shortcut window to run the shortcut. Ensure that all the added apps open hidden as intended. If so, move on to the next section.

Create a Master Login Script

The next phase is to use a little light scripting to make this shortcut run upon every login.

Open Terminal. If you don’t already have a designated folder for scripts, I recommend creating one in your home folder with another child directory specifically for shell scripts. Do so by issuing the following terminal command

mkdir -p ~/scripts/shell_scripts 

Now that you’ve created your shell script directory, create and edit your actual login script with this command:


nano ~/scripts/shell_scripts/my_login_script.sh

Upon issuing the command above, you’ll be greeted with nano’s editing interface. Copy the following into the text field.


shortcuts run "Kipps Minimized Login Items"

Make sure to replace the “Kipps Minimized Login Items” text with the name of the Shortcut you settled on.

Press Command+O, then the Enter key to save the edits you made. You may then exit nano by pressing Commanf+X. Next, you need to make the script you just made executable by issuing the following command.

sudo chmod +x ~/scripts/shell_scripts/my_login_script.sh

Upon issuing the command, you will be prompted to provide your password. Go ahead and enter it. Voilà, your login script is now executable. Now, you want to test it by running it using the following command:

bin/zsh ~/scripts/shell_scripts/my_login_script.sh

If it runs successfully, you’re ready to move on to the next phase, making sure your script runs on login automatically.


Running the Script on Login

To trigger the running of your script upon login, we are going to modify your .profile file. If you’ve never worked with this file before, you may need to create it. Luckily, the Terminal commands to both create and edit this file are one and the same:

nano ~/.profile

Paste the following into the text field, replacing “YOUR_LOCAL_USERNAME” with your username as it appears in your home directory. By default, this is whatever your username is but without any capital letters.


USER="YOUR_LOCAL_USERNAME"

if ( -f /Users/"$USER"/Scripts/Bash\ Scripts/my_login_script.sh ); then
    /Users/"$USER"/Scripts/Bash\ Scripts/my_login_script.sh
fi

Editing your profile file to run your script on login.

Press Comand+O, followed by the Enter key to save the file. Then, press Command+X to exit nano.


There you have it! The login script we made will now run automatically every time you log in, which will, in turn, run our Shortcut for opening login items minimized. To test the final configuration, log out fully and log back in. Keep in mind that your first run will most likely prompt you to grant permissions for your login script.

Once you do, go ahead and log out and back in once again. With the requisite permissions granted, your login script will now execute as intended.


One of the core appeals of macOS is the cleanliness of its interface. Using the traditional means of opening applications on login can have the effect of adding clutter and visual noise at the outset of your work session.

By using this Shortcut and scripting procedures outlined above, you can easily reclaim a clean startup environment without compromising on having your startup applications open and ready to go in the background.


[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *