-
-
Notifications
You must be signed in to change notification settings - Fork 19
OSL ‐ File Handling
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
)
Info About files structure here
The following commands and file attributes facilitate file management and manipulation within the OriginOS environment, allowing users to work with files effectively:
-
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:
Examples:
file "open" (file-path or file-uuid or file-name)
file "open" "test.osl" file "open" user_folder ++ "/Downloads/test.txt"
-
Open File by ID (
file "open" "id"
)- Opens a file with the specified "file-id" for modification.
- Syntax:
file "open" "id" file-id
-
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
-
Start Default Application for File (
file "start"
)- Runs/opens the current file in its default application.
- Syntax:
file "start"
-
Render File (
file "render"
)- Renders the currently open file.
- Syntax:
You can add "interactable" at the end of this command to render it as a file instead of as an icon.
file "render" size
-
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
-
Get File Entry (
file "get"
)- Gets a specific file entry based on the data ID.
- Syntax:
file "get" data-id
-
Set File Entry (
file "set"
)- Sets a specific file entry based on the data ID.
- Syntax:
file "set" data-id
-
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"
-
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
-
Access Current File Path (
current_file_path
)- Retrieves the file path of the current window's app file.
- Usage:
current_file_path
-
Access Current File UUID (
current_file_uuid
)- Retrieves the UUID of the current file.
- Usage:
current_file_uuid
These commands and attributes provide extensive capabilities for file handling within the OriginOS environment, empowering users to manage, open, render, and interact with files seamlessly.
Thank you for providing additional information. Let's incorporate it into the documentation:
- The "file" variable stores metadata about the opened file, accessible as an array. For instance,
file[1]
retrieves the file type, whilefile[2]
fetches the file name. Refer to the documentation link for the complete index breakdown.
- 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.
- The
file "download"
command downloads a file to the downloads folder by default. Adding a "path" parameter allows choosing a specific destination. For example:This command creates a text file named "test.txt" in the "system" folder.file "download" "test.txt" "" "hello, world" "origin/(A) system"
- When rendering a file as interactable, users can drag it to initiate drag-and-drop actions or click to open the file.
- The
file "get"
command sets the "data" variable to a specific index in the file data. For example:This logs the name of the currently open file.file "get" "2" log data
- Using the
rightclick
action allows specifying interactable objects to bring up the right-click menu for specific files, enhancing user interaction.
- 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.
Let me know if you need further clarification or if there's anything else to add!
originOS is a web desktop gui with a self contained file system, programming languages, internet system and a whole lot of stuff an os should be able to do Use originOS here