Skip to content

OSL ‐ File Handling

Mistium edited this page Mar 12, 2024 · 15 revisions

Getting Files That have been drag and dropped onto your application

The file_dropped variable is a file uuid

// detect if the file has been dropped
if file_dropped != 0 (
  file "open" file_dropped
  // attempt to open the file (you may need file editor/viewer permissions)

  file_dropped = 0
  // reset the file dropped variable so that you only run this code once a file is dropped and not repeatedly
)

if you are modifying files you will NEED to read the page linked below

Info About files structure here

Supported File Commands:

File Management and Manipulation Commands

The following commands and file attributes facilitate file management and manipulation within the OriginOS environment, allowing users to work with files effectively:

  1. Open File (file "open")

    • Opens the selected file to be modified.
    • Sets the "file" variable to the raw JSON of the current file.
    • Sets the "data" variable to the data value of the open file.
    • Syntax:
      file "open" (file-path or file-uuid or file-name)
      Examples:
      file "open" user_folder ++ "/Downloads/test.txt"
      
      // only open the file and do not set the file and data variable
      file "open" user_folder ++ "/Downloads/test.txt" "onlyaccess"
  2. Open File by ID (file "open" "id")

    • Opens a file with the specified "file-id" for modification.
    • Syntax:
      file "open" "id" file-id
  3. Check File Existence (file "exists")

    • Returns a boolean indicating whether a file exists and is accessible by the current program.
    • Syntax:
      file "exists" file-path
  4. Start Default Application for File (file "start")

    • Runs/opens the current file in its default application.
    • Syntax:
      file "start"
  5. Render File (file "render")

    • Renders the currently open file.
    • Syntax:
      file "render" size
      You can add "interactable" at the end of this command to render it as a file instead of as an icon.
  6. Download File (file "download")

    • Adds a file to the downloads folder.
    • Syntax (v4.5.1):
      file "download" "file_name.file_extension" "icon_code" "file_data" "path"
    • Examples:
      file "download" "test.txt" null "hello world!" user_folder ++ "/Downloads"
      // adds a text file to the downloads folder
  7. Get File Entry (file "get")

    • Gets a specific file entry based on the data ID.
    • Syntax:
      file "get" data-id
  8. Set File Entry (file "set")

    • Sets a specific file entry based on the data ID.
    • Syntax:
      file "set" data-id
  9. Right-Click Action (rightclick)

    • Represents a right-click action on a file, text, or window with specified IDs.
    • Syntax:
      rightclick "file/text/window" "file-id/text/window-id"
  10. Install File Type (file "install_type")

    • Adds a new file type to the OS system.
    • Syntax (v4.3.7):
      file "install_type" type_code file_type_icon file_type
  11. Access Current File Path (current_file_path)

    • Retrieves the file path of the current window's app file.
    • Usage:
      current_file_path
  12. Access Current File UUID (current_file_uuid)

    • Retrieves the UUID of the current file.
    • Usage:
      current_file_uuid
  13. Closing an Opened File (file "close"):

  • The file "close" command closes the currently opened file, ending the editing session and freeing up resources.
  • Syntax:
    file "close"
  • This command is useful for concluding file editing operations and ensuring proper resource management within the OriginOS environment.

1. Purpose of Setting "file" and "data" Variables:

  • The "file" variable stores metadata about the opened file, accessible as an array. For instance, file[1] retrieves the file type, while file[2] fetches the file name. Refer to the documentation link for the complete index breakdown.

2. Resetting "file_dropped" Variable:

  • After processing a dropped file, resetting file_dropped to 0 prevents continuous execution of the file processing code every frame, ensuring it runs only once per dropped file event.

3. Handling File Paths in "file "download"":

  • The file "download" command downloads a file to the downloads folder by default. Adding a "path" parameter allows choosing a specific destination. For example:
    file "download" "test.txt" "" "hello, world" "origin/(A) system"
    This command creates a text file named "test.txt" in the "system" folder.

4. Rendering Files as Interactable:

  • When rendering a file as interactable, users can drag it to initiate drag-and-drop actions or click to open the file.

5. Usage of "file "get"":

  • The file "get" command sets the "data" variable to a specific index in the file data. For example:
    file "get" "2"
    log data
    This logs the name of the currently open file.

6. Purpose of "rightclick" Action:

  • Using the rightclick action allows specifying interactable objects to bring up the right-click menu for specific files, enhancing user interaction.

7. Functionality of "file "install_type"":

  • The file "install_type" command enriches the OS system by adding new file types. It defines icons for file types, ensuring consistent representation throughout the system, and sets default applications for handling those file types. This streamlines file management and enhances user experience.

originOS Wiki

Wiki Views: :views


OSL | OTS | ICN | OASM

Clone this wiki locally